Skip to content

Instantly share code, notes, and snippets.

@gregworley
gregworley / composite literal expansion
Created April 28, 2011 16:54
From Gary Burd's Oauth.go package
var noEscape = [256]bool{
'A': true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
'a': true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
'0': true, true, true, true, true, true, true, true, true, true,
'-': true,
'.': true,
'_': true,
'~': true,
}
package main
import "fmt"
func main() {
m := make(map[string]int) //initialize
//map[keyType]valueType
m["Alice"] = 21 //Store Values to initialized
#python 3.1
x = 'hello'
y = 'world'
print(x + " " + y)
// go/doc/GoCourseDay1.pdf Initialization example
package transcendental
import "math"
var Pi float64
func init() {
Pi = 4 * math.Atan(1) //init() function computes Pi
}
// go/doc/GoCourseDay1.pdf slide 62
package main
import (
"fmt"
"./transcendental"
)
var twoPi = 2 * transcendental.Pi //decl computes twoPi
func main() {
// A version of echo - go/docs/GoCourseDay1.pdf slide 59
package main
import (
"fmt"
"os"
)
func main() {
package file
import (
"os"
"syscall"
)
type File struct {
fd int // file descriptor number
name string //file name at Open time
package main
import (
"./iopkg"
"fmt"
"os"
)
func main() {
hello := []byte("hello, world\n")
package main
import (
"os"
"flag" // command line option parser
)
var omitNewline = flag.Bool("n", false, "don't print final newline")
const (
package main
import "fmt"
func f() {
for i := 0; i < 10; i++ {
g := func(i int) {
fmt.Printf("%d", i)
}
g(i)