TRIVIAL go fmt

This commit is contained in:
Dan Buch 2012-11-10 13:41:33 -05:00
parent ab9db7837d
commit 447c40aebd
2 changed files with 99 additions and 99 deletions

View File

@ -1,29 +1,29 @@
package main package main
import ( import (
"fmt" "fmt"
"time" "time"
) )
func main() { func main() {
c := make(chan int, 2) c := make(chan int, 2)
q := make(chan bool) q := make(chan bool)
go func(c chan int) { go func(c chan int) {
for i := range c { for i := range c {
fmt.Println("\t", i, "<- popped") fmt.Println("\t", i, "<- popped")
time.Sleep(300 * time.Millisecond) time.Sleep(300 * time.Millisecond)
} }
}(c) }(c)
go func(c chan int) { go func(c chan int) {
i := 0 i := 0
for { for {
c <- i c <- i
fmt.Println("pushed ->", i) fmt.Println("pushed ->", i)
i += 1 i += 1
} }
}(c) }(c)
<-q <-q
} }

View File

@ -1,97 +1,97 @@
package main package main
import ( import (
"fmt" "fmt"
"io" "io"
"os" "os"
"strings" "strings"
) )
var lookupTable = map[byte]byte{ var lookupTable = map[byte]byte{
'A': 'N', 'A': 'N',
'B': 'O', 'B': 'O',
'C': 'P', 'C': 'P',
'D': 'Q', 'D': 'Q',
'E': 'R', 'E': 'R',
'F': 'S', 'F': 'S',
'G': 'T', 'G': 'T',
'H': 'U', 'H': 'U',
'I': 'V', 'I': 'V',
'J': 'W', 'J': 'W',
'K': 'X', 'K': 'X',
'L': 'Y', 'L': 'Y',
'M': 'Z', 'M': 'Z',
'N': 'A', 'N': 'A',
'O': 'B', 'O': 'B',
'P': 'C', 'P': 'C',
'Q': 'D', 'Q': 'D',
'R': 'E', 'R': 'E',
'S': 'F', 'S': 'F',
'T': 'G', 'T': 'G',
'U': 'H', 'U': 'H',
'V': 'I', 'V': 'I',
'W': 'J', 'W': 'J',
'X': 'K', 'X': 'K',
'Y': 'L', 'Y': 'L',
'Z': 'M', 'Z': 'M',
'a': 'n', 'a': 'n',
'b': 'o', 'b': 'o',
'c': 'p', 'c': 'p',
'd': 'q', 'd': 'q',
'e': 'r', 'e': 'r',
'f': 's', 'f': 's',
'g': 't', 'g': 't',
'h': 'u', 'h': 'u',
'i': 'v', 'i': 'v',
'j': 'w', 'j': 'w',
'k': 'x', 'k': 'x',
'l': 'y', 'l': 'y',
'm': 'z', 'm': 'z',
'n': 'a', 'n': 'a',
'o': 'b', 'o': 'b',
'p': 'c', 'p': 'c',
'q': 'd', 'q': 'd',
'r': 'e', 'r': 'e',
's': 'f', 's': 'f',
't': 'g', 't': 'g',
'u': 'h', 'u': 'h',
'v': 'i', 'v': 'i',
'w': 'j', 'w': 'j',
'x': 'k', 'x': 'k',
'y': 'l', 'y': 'l',
'z': 'm', 'z': 'm',
} }
type rot13Reader struct { type rot13Reader struct {
reader io.Reader reader io.Reader
} }
func (rot *rot13Reader) Read(p []byte) (i int, err error) { func (rot *rot13Reader) Read(p []byte) (i int, err error) {
if len(p) == 0 { if len(p) == 0 {
return 0, nil return 0, nil
} }
buf := make([]byte, len(p)) buf := make([]byte, len(p))
i, err = rot.reader.Read(buf) i, err = rot.reader.Read(buf)
var ( var (
b, c byte b, c byte
found bool found bool
) )
for i := range buf { for i := range buf {
b = buf[i] b = buf[i]
c, found = lookupTable[b] c, found = lookupTable[b]
if found { if found {
p[i] = c p[i] = c
} else { } else {
p[i] = b p[i] = b
} }
} }
return return
} }
func main() { func main() {
s := strings.NewReader("Lbh penpxrq gur pbqr!") s := strings.NewReader("Lbh penpxrq gur pbqr!")
r := rot13Reader{s} r := rot13Reader{s}
io.Copy(os.Stdout, &r) io.Copy(os.Stdout, &r)
fmt.Println("") fmt.Println("")
} }