...
Code Block |
---|
package main import ( "fmt" "error" "math" ) func main() { result, err := sqrt(16) if err != nil { fmt.Println(err) } else { fmt.Println(result) } } func sqrt(x float64) (float64, error ) { if x < 0 { return 0, errors.New("Undefined for negative numbers") } return math.Sqrt(x), nil } |
Structs/Types
Code Block |
---|
package main
import (
"fmt"
)
type person struct {
name string
age int
}
func main(){
p:= person{name: "Jake", age: 23 }
fmt.Println(p)
} |
Commands
Command | Description |
---|---|
go run <src.go> | Run some code |
go build | Compile the code. Outputs to local folder. Executable has folder as name. |
go install | Compiles and places the output in workspace/bin |
go env GOPATH | Outputs the default workspace folder |
...
Code Block |
---|
package main import ( "fmt" ) func main(){ var x int x = 5 fmt.Println(x) } |
Structs
Code Block |
---|
References
Reference | URL |
---|---|
Learn Go in 12 Minutes | https://www.youtube.com/watch?v=C8LgvuEBraI |
Go Packages | https://golang.org/pkg/ |
Go By Examples | https://gobyexample.com/ |
...