-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgolang.go
45 lines (35 loc) · 994 Bytes
/
golang.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Go Programming Notes
// Resources
// - By by Example https://gobyexample.com/
// - An Introduction to Programming in Go http://www.golang-book.com/books/intro
// - Effective Go https://golang.org/doc/effective_go.html
// To run Go program
// $ mkdir pkgname
// $ cd pkgname
// $ go build
// Standardized formatting of Go programs
// $ gofmt goprogram.go
package main
import (
"fmt" // I/O function
"math" // Basic constants and math functions
"math/rand" // Pseudo-random number generators
)
// Functions can take zero or more arguments
func add(x int, y int) int {
return x + y
}
// If params of same time, you can omit all but last type call
func subtract(x, y int) int {
return x - y
}
func main() {
rand.Seed(3123)
fmt.Println("My favorite number is", rand.Intn(6))
// Exported names are capitalized
// fmt.Println(math.pi) <- this fails
fmt.Println(math.Pi)
// Call previously defined functions
fmt.Println(add(42, 13))
fmt.Println(subtract(42, 13))
}