]> Cypherpunks repositories - gostls13.git/commitdiff
doc/progs: gofmt -w
authorMikio Hara <mikioh.mikioh@gmail.com>
Sat, 9 Jul 2011 10:16:45 +0000 (20:16 +1000)
committerRob Pike <r@golang.org>
Sat, 9 Jul 2011 10:16:45 +0000 (20:16 +1000)
R=r, gri, r
CC=golang-dev
https://golang.org/cl/4662085

13 files changed:
doc/progs/echo.go
doc/progs/file_windows.go
doc/progs/helloworld.go
doc/progs/helloworld3.go
doc/progs/print.go
doc/progs/server.go
doc/progs/server1.go
doc/progs/sieve.go
doc/progs/sieve1.go
doc/progs/sort.go
doc/progs/sortmain.go
doc/progs/strings.go
doc/progs/sum.go

index 84470ddb9c5ce815b63e401693211ff69a260e33..3260edd747a00a04254816d728f927f842e81f1b 100644 (file)
@@ -6,18 +6,18 @@ package main
 
 import (
        "os"
-       "flag"  // command line option parser
+       "flag" // command line option parser
 )
 
 var omitNewline = flag.Bool("n", false, "don't print final newline")
 
 const (
-       Space = " "
+       Space   = " "
        Newline = "\n"
 )
 
 func main() {
-       flag.Parse()   // Scans the arg list and sets up flags
+       flag.Parse() // Scans the arg list and sets up flags
        var s string = ""
        for i := 0; i < flag.NArg(); i++ {
                if i > 0 {
index d5e7c00d3c8a3a90e14e66a105330a21f779e901..03003a3f71cb096a3892e0c094f00e8f8eae8801 100644 (file)
@@ -10,8 +10,8 @@ import (
 )
 
 type File struct {
-       fd   syscall.Handle    // file descriptor number
-       name string // file name at Open time
+       fd   syscall.Handle // file descriptor number
+       name string         // file name at Open time
 }
 
 func newFile(fd syscall.Handle, name string) *File {
index 637a0956b8630e5b849dc79fc2ec572dabc044ed..8185038d989bfcdabdd5a90ed4303770150ec405 100644 (file)
@@ -4,7 +4,7 @@
 
 package main
 
-import fmt "fmt"  // Package implementing formatted I/O.
+import fmt "fmt" // Package implementing formatted I/O.
 
 func main() {
        fmt.Printf("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界\n")
index 5bb0be2184f1a45a66bf009691e68d796c4f19ba..2011513b73541ea6c671016fa3263f9f1168df7d 100644 (file)
@@ -15,7 +15,7 @@ func main() {
        file.Stdout.Write(hello)
        f, err := file.Open("/does/not/exist")
        if f == nil {
-               fmt.Printf("can't open file; err=%s\n",  err.String())
+               fmt.Printf("can't open file; err=%s\n", err.String())
                os.Exit(1)
        }
 }
index 69c35a532ace75292d3427c533a3dfa6c6a8227a..8f44ba8c61034bc68d11e002db38f53e2f6e3a27 100644 (file)
@@ -7,7 +7,7 @@ package main
 import "fmt"
 
 func main() {
-       var u64 uint64 = 1<<64-1
+       var u64 uint64 = 1<<64 - 1
        fmt.Printf("%d %d\n", u64, int64(u64))
 
        // harder stuff
index f3a6b18897661b19e230544d2f4f8555fc8cdfa1..b498b53a63c8bc034ba0214725898a267c23393b 100644 (file)
@@ -7,8 +7,8 @@ package main
 import "fmt"
 
 type request struct {
-       a, b    int
-       replyc  chan int
+       a, b   int
+       replyc chan int
 }
 
 type binOp func(a, b int) int
@@ -21,7 +21,7 @@ func run(op binOp, req *request) {
 func server(op binOp, service chan *request) {
        for {
                req := <-service
-               go run(op, req)  // don't wait for it
+               go run(op, req) // don't wait for it
        }
 }
 
@@ -42,8 +42,8 @@ func main() {
                req.replyc = make(chan int)
                adder <- req
        }
-       for i := N-1; i >= 0; i-- {   // doesn't matter what order
-               if <-reqs[i].replyc != N + 2*i {
+       for i := N - 1; i >= 0; i-- { // doesn't matter what order
+               if <-reqs[i].replyc != N+2*i {
                        fmt.Println("fail at", i)
                }
        }
index b8c09269b7c61fb50fd27ccb25bcbf888739bba6..a4093924b8ec21e8f47eb35a1c5743a2dce4bad0 100644 (file)
@@ -7,8 +7,8 @@ package main
 import "fmt"
 
 type request struct {
-       a, b    int
-       replyc  chan int
+       a, b   int
+       replyc chan int
 }
 
 type binOp func(a, b int) int
@@ -22,7 +22,7 @@ func server(op binOp, service chan *request, quit chan bool) {
        for {
                select {
                case req := <-service:
-                       go run(op, req)  // don't wait for it
+                       go run(op, req) // don't wait for it
                case <-quit:
                        return
                }
@@ -47,8 +47,8 @@ func main() {
                req.replyc = make(chan int)
                adder <- req
        }
-       for i := N-1; i >= 0; i-- {   // doesn't matter what order
-               if <-reqs[i].replyc != N + 2*i {
+       for i := N - 1; i >= 0; i-- { // doesn't matter what order
+               if <-reqs[i].replyc != N+2*i {
                        fmt.Println("fail at", i)
                }
        }
index c7c3e78122221da0d137269a3edf671261ed843b..b315309819d93048fc9b8f35bd6ad34181358210 100644 (file)
@@ -9,7 +9,7 @@ import "fmt"
 // Send the sequence 2, 3, 4, ... to channel 'ch'.
 func generate(ch chan int) {
        for i := 2; ; i++ {
-               ch <- i  // Send 'i' to channel 'ch'.
+               ch <- i // Send 'i' to channel 'ch'.
        }
 }
 
@@ -17,17 +17,17 @@ func generate(ch chan int) {
 // removing those divisible by 'prime'.
 func filter(in, out chan int, prime int) {
        for {
-               i := <-in  // Receive value of new variable 'i' from 'in'.
-               if i % prime != 0 {
-                       out <- i  // Send 'i' to channel 'out'.
+               i := <-in // Receive value of new variable 'i' from 'in'.
+               if i%prime != 0 {
+                       out <- i // Send 'i' to channel 'out'.
                }
        }
 }
 
 // The prime sieve: Daisy-chain filter processes together.
 func main() {
-       ch := make(chan int)  // Create a new channel.
-       go generate(ch)  // Start generate() as a goroutine.
+       ch := make(chan int)       // Create a new channel.
+       go generate(ch)            // Start generate() as a goroutine.
        for i := 0; i < 100; i++ { // Print the first hundred primes.
                prime := <-ch
                fmt.Println(prime)
index e785e203557fbd77fcbb1544dba70abfc9669c27..e1411a33467c16c0dea3c449cc9fdf975b9ccc94 100644 (file)
@@ -9,7 +9,7 @@ import "fmt"
 // Send the sequence 2, 3, 4, ... to returned channel 
 func generate() chan int {
        ch := make(chan int)
-       go func(){
+       go func() {
                for i := 2; ; i++ {
                        ch <- i
                }
@@ -22,7 +22,7 @@ func filter(in chan int, prime int) chan int {
        out := make(chan int)
        go func() {
                for {
-                       if i := <-in; i % prime != 0 {
+                       if i := <-in; i%prime != 0 {
                                out <- i
                        }
                }
index 47df9b3513395ee02c39a4e1f93bda9ecb262c6b..894693f0d53ca5289d3b46ea8152b9f15ba0912d 100644 (file)
@@ -21,7 +21,7 @@ func Sort(data Interface) {
 func IsSorted(data Interface) bool {
        n := data.Len()
        for i := n - 1; i > 0; i-- {
-               if data.Less(i, i - 1) {
+               if data.Less(i, i-1) {
                        return false
                }
        }
@@ -32,32 +32,28 @@ func IsSorted(data Interface) bool {
 
 type IntSlice []int
 
-func (p IntSlice) Len() int            { return len(p) }
-func (p IntSlice) Less(i, j int) bool  { return p[i] < p[j] }
-func (p IntSlice) Swap(i, j int)       { p[i], p[j] = p[j], p[i] }
-
+func (p IntSlice) Len() int           { return len(p) }
+func (p IntSlice) Less(i, j int) bool { return p[i] < p[j] }
+func (p IntSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
 
 type Float64Slice []float64
 
-func (p Float64Slice) Len() int            { return len(p) }
-func (p Float64Slice) Less(i, j int) bool  { return p[i] < p[j] }
-func (p Float64Slice) Swap(i, j int)       { p[i], p[j] = p[j], p[i] }
-
+func (p Float64Slice) Len() int           { return len(p) }
+func (p Float64Slice) Less(i, j int) bool { return p[i] < p[j] }
+func (p Float64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
 
 type StringSlice []string
 
-func (p StringSlice) Len() int            { return len(p) }
-func (p StringSlice) Less(i, j int) bool  { return p[i] < p[j] }
-func (p StringSlice) Swap(i, j int)       { p[i], p[j] = p[j], p[i] }
-
+func (p StringSlice) Len() int           { return len(p) }
+func (p StringSlice) Less(i, j int) bool { return p[i] < p[j] }
+func (p StringSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
 
 // Convenience wrappers for common cases
 
-func SortInts(a []int)        { Sort(IntSlice(a)) }
-func SortFloat64s(a []float64)    { Sort(Float64Slice(a)) }
-func SortStrings(a []string)  { Sort(StringSlice(a)) }
-
+func SortInts(a []int)         { Sort(IntSlice(a)) }
+func SortFloat64s(a []float64) { Sort(Float64Slice(a)) }
+func SortStrings(a []string)   { Sort(StringSlice(a)) }
 
-func IntsAreSorted(a []int) bool       { return IsSorted(IntSlice(a)) }
-func Float64sAreSorted(a []float64) bool   { return IsSorted(Float64Slice(a)) }
-func StringsAreSorted(a []string) bool { return IsSorted(StringSlice(a)) }
+func IntsAreSorted(a []int) bool         { return IsSorted(IntSlice(a)) }
+func Float64sAreSorted(a []float64) bool { return IsSorted(Float64Slice(a)) }
+func StringsAreSorted(a []string) bool   { return IsSorted(StringSlice(a)) }
index 28eec8d4f8a38a58ffd6822a3744f95cf926b9c1..c1babb01f81f0d3f5cc63c609087d1072fd3c7b4 100644 (file)
@@ -28,27 +28,27 @@ func strings() {
 }
 
 type day struct {
-       num        int
-       shortName  string
-       longName   string
+       num       int
+       shortName string
+       longName  string
 }
 
 type dayArray struct {
        data []*day
 }
 
-func (p *dayArray) Len() int            { return len(p.data) }
-func (p *dayArray) Less(i, j int) bool  { return p.data[i].num < p.data[j].num }
-func (p *dayArray) Swap(i, j int)       { p.data[i], p.data[j] = p.data[j], p.data[i] }
+func (p *dayArray) Len() int           { return len(p.data) }
+func (p *dayArray) Less(i, j int) bool { return p.data[i].num < p.data[j].num }
+func (p *dayArray) Swap(i, j int)      { p.data[i], p.data[j] = p.data[j], p.data[i] }
 
 func days() {
-       Sunday :=    day{0, "SUN", "Sunday"}
-       Monday :=    day{1, "MON", "Monday"}
-       Tuesday :=   day{2, "TUE", "Tuesday"}
+       Sunday := day{0, "SUN", "Sunday"}
+       Monday := day{1, "MON", "Monday"}
+       Tuesday := day{2, "TUE", "Tuesday"}
        Wednesday := day{3, "WED", "Wednesday"}
-       Thursday :=  day{4, "THU", "Thursday"}
-       Friday :=    day{5, "FRI", "Friday"}
-       Saturday :=  day{6, "SAT", "Saturday"}
+       Thursday := day{4, "THU", "Thursday"}
+       Friday := day{5, "FRI", "Friday"}
+       Saturday := day{6, "SAT", "Saturday"}
        data := []*day{&Tuesday, &Thursday, &Wednesday, &Sunday, &Monday, &Friday, &Saturday}
        a := dayArray{data}
        sort.Sort(&a)
index 2cdb6101a09aac4f8f672a30bed462b263449e5d..e6739b3851c239d019dd08fe8bbd2ed4f925816c 100644 (file)
@@ -8,7 +8,9 @@ import "os"
 
 func main() {
        s := "hello"
-       if s[1] != 'e' { os.Exit(1) }
+       if s[1] != 'e' {
+               os.Exit(1)
+       }
        s = "good bye"
        var p *string = &s
        *p = "ciao"
index 9caa799fdd5b19859490f67e56d3cf6178e50a88..e022195ed5d8cb9ca2137b994702eb6e3b5d7353 100644 (file)
@@ -14,7 +14,6 @@ func sum(a []int) int { // returns an int
        return s
 }
 
-
 func main() {
        s := sum([3]int{1, 2, 3}[:]) // a slice of the array is passed to sum
        fmt.Print(s, "\n")