Go Basics: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
No edit summary  | 
				|||
| Line 20: | Line 20: | ||
go install  | go install  | ||
go run  | go run  | ||
</pre>  | |||
== Hello World ==  | |||
<pre>  | |||
// hello.go  | |||
package main  | |||
import (     | |||
    "fmt"  | |||
    "os"  | |||
    "strings"  | |||
)  | |||
func main() {  | |||
    who := "World!"    | |||
    if len(os.Args) > 1 { /* os.Args[0] is "hello" or "hello.exe" */    | |||
        who = strings.Join(os.Args[1:], " ")    | |||
    }  | |||
    fmt.Println("Hello", who)    | |||
}  | |||
</pre>  | </pre>  | ||
Revision as of 00:53, 6 February 2014
Resources: http://golang.org/
Install and Setup
sudo apt-get install golang
http://golang.org/doc/code.html discusses setting up the GOLANG environment variable and your code repository
mkdir -p $HOME/projects/go/src export GOPATH=$HOME/projects/go (add this to .profile too)
Commands
godoc go build go install go run
Hello World
// hello.go
package main
import (   
    "fmt"
    "os"
    "strings"
)
func main() {
    who := "World!"  
    if len(os.Args) > 1 { /* os.Args[0] is "hello" or "hello.exe" */  
        who = strings.Join(os.Args[1:], " ")  
    }
    fmt.Println("Hello", who)  
}