github.com/likebike/go--@v0.0.0-20190911215757-0bd925d16e96/test.go (about) 1 #!go/bin/go run 2 //^^^^^^^^^^^^^ "shebang" support enables you to run Go programs as scripts. 3 // I usually like to say something like "#!/usr/bin/env go run", 4 // but on Linux a shebang command can only have ONE argument, so 5 // the kernel tries to run "go run" as a command, which fails. 6 // (BSD and MacOSX don't have this problem.) 7 // We *could* create a "go run" binary as part of Go-- to enable this 8 // in a cross-platform sort of way, but for now I just use this 9 // relative path. You'll need to run from this directory. 10 11 package main 12 13 import ( 14 "fmt" 15 "net/http" 16 "encoding/json" 17 "os" // Unused imports now generate Warnings instead of Errors. 18 ) 19 20 type T1 struct { n1,n2 int } 21 22 func // I'm not saying that this is actually a good way to style your function definitions... 23 (t T1) // I'm only saying that you should be allowed to do it if you want to. 24 crazy_func_style 25 (in1,in2 int) 26 (out1,out2 int) 27 { 28 return 3,4 29 } 30 31 func main() { 32 fmt.Println("\nWelcome to Go--. Don't worry about those warnings that you see above -- they are a *feature*, not a bug!") 33 fmt.Println("Go-- gives you some extra abilities, compared to normal Go:\n") 34 35 unused:=5 36 fmt.Println(" * Unused variables and imports now generate Warnings (like you see above) instead of Errors.\n") 37 38 http.Header{}.clone(); _=http.response{}.status; http.htmlEscape("We can access <em>everything</em>!") 39 fmt.Println(" * You can access unexported symbols.\n") 40 41 var a,b T1; a.n1,a.n2=8,9 42 bs,err:=json.Marshal(a); if err!=nil { panic(err) } 43 err=json.Unmarshal(bs, &b); if err!=nil { panic(err) } 44 if b.n1!=8 || b.n2!=9 { panic("json was unable to read/set unexported field!") } 45 fmt.Println(" * encoding/json can un/marshal unexported fields.\n") 46 47 if 0>1 { } // Comments here are fine too. 48 else { fmt.Println(" * More flexible whitespace in 'if' statements; `if cond {...} \\n else {...}` is now a valid syntax.\n") } 49 50 three,four:=a.crazy_func_style(1,2); if three!=3 || four!=4 { panic("Incorrect crazy_func_style outputs!") } 51 fmt.Println(" * More flexible whitespace in function definitions.\n") 52 53 fmt.Println(" * You can use a 'shebang' line (#!...) to run your Go-- programs as scripts.\n") 54 55 fmt.Println("Remember: with great power comes great responsiblity. Have fun!\n") 56 } 57