├── basic └── helloworld.go ├── typeinf └── typeinf.go ├── forloop └── forimproved.go ├── exportedname └── exported-names.go ├── imports └── imports.go ├── variables └── variables.go ├── sandbox └── sandbox.go ├── functions └── functions.go ├── variableinit └── variableinit.go ├── multres └── multres.go ├── packages └── packages.go ├── shortdeclaration └── shortdeclaration.go ├── typeconversion └── typeconversion.go ├── nakedreturn └── nakedreturn.go ├── numericonstant └── numericonstant.go └── README.md /basic/helloworld.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main(){ 6 | fmt.Printf("Hello, world!\n") 7 | } 8 | 9 | -------------------------------------------------------------------------------- /typeinf/typeinf.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | x := 40.322232323 9 | fmt.Printf("Type of i is %T \n", x) 10 | } 11 | -------------------------------------------------------------------------------- /forloop/forimproved.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | sum := 1 7 | for sum < 100 { 8 | sum += sum 9 | fmt.Println(sum) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /exportedname/exported-names.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | func main() { 9 | fmt.Printf("The value of pi is %0.2f \n", math.Pi) 10 | } 11 | -------------------------------------------------------------------------------- /imports/imports.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | func main() { 9 | fmt.Printf("The factored import gives %g", math.Sqrt(16), "\n") 10 | } 11 | -------------------------------------------------------------------------------- /variables/variables.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | var c, python, java bool 8 | 9 | func main() { 10 | var i int 11 | fmt.Println(i, c, python, java) 12 | } 13 | -------------------------------------------------------------------------------- /sandbox/sandbox.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func main() { 9 | fmt.Println("Welcome to the playground") 10 | 11 | fmt.Println("The time is ::", time.Now()) 12 | } 13 | -------------------------------------------------------------------------------- /functions/functions.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func add(x, y int) int { 8 | return x + y 9 | } 10 | 11 | func main() { 12 | fmt.Println("The addition of x and y is ", add(4, 6)) 13 | } 14 | -------------------------------------------------------------------------------- /variableinit/variableinit.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | var i, j int = 2, 3 8 | 9 | func main() { 10 | var c, python, java = true, false, "no!" 11 | fmt.Println(i, j, c, python, java) 12 | } 13 | -------------------------------------------------------------------------------- /multres/multres.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func swap(x, y string) (string, string) { 8 | return y, x 9 | } 10 | 11 | func main() { 12 | a, b := swap("World", "Hello") 13 | fmt.Println(a, b) 14 | } 15 | -------------------------------------------------------------------------------- /packages/packages.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | ) 7 | 8 | func main() { 9 | fmt.Println("This is a program related to packages...") 10 | fmt.Println("The random number generated is ", rand.Float32()) 11 | } 12 | -------------------------------------------------------------------------------- /shortdeclaration/shortdeclaration.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | var i, j int = 2, 3 9 | k := 4 // ':=' is short assignment operator, used instead of implicit type 10 | 11 | fmt.Println(i, j, k) 12 | } 13 | -------------------------------------------------------------------------------- /typeconversion/typeconversion.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | func main() { 9 | var x, y int = 2, 4 10 | var f float64 = math.Sqrt(float64(x*x + y*y)) 11 | z := f 12 | fmt.Printf("%v %v %0.2f \n", x, y, z) 13 | } 14 | -------------------------------------------------------------------------------- /nakedreturn/nakedreturn.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func split(sum int) (x, y int) { 8 | x = sum * 4 / 9 9 | y = sum - x 10 | return //A naked return here, without any arguments: It would return both x and y 11 | } 12 | 13 | func main() { 14 | fmt.Println(split(18)) 15 | } 16 | -------------------------------------------------------------------------------- /numericonstant/numericonstant.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | //much larger value than int64 6 | const myConst = 9223372036854775808543522345 7 | 8 | // We add int64, limiting the number program will no longer compile 9 | // Error: github.com/golang_learn/numericonstant/numericonstant.go:9: constant 9223372036854775808543522345 overflows int64 10 | const myConst1 int64 = 9223372036854775808543522345 11 | 12 | func main() { 13 | fmt.Println("Compiling...") 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Repository of sources, codes while learning GoLang 2 | 3 |
4 |
5 | 6 | __Installing Go in Linux:__ 7 | - Download the binary (_At the time of writing version is 1.8.1_): `wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz` 8 | 9 | *** 10 | 11 | __Sources:__ 12 | 1. [GoLang website](https://golang.org/) 13 | 2. [GoLang installation](https://www.digitalocean.com/community/tutorials/how-to-install-go-1-6-on-ubuntu-16-04) 14 | [2.a] [GoLang Install](http://ganeshramr.github.io/normal/2015/03/29/goerror1.html) 15 | 3. [Tour of Go](https://tour.golang.org/list) 16 | 4. [GoLang Jupyter notebook](http://www.datadan.io/announcing-a-golang-kernel-for-jupyter-notebooks/) 17 | 5. [GoLang Jupyter Kernel-github.com](https://github.com/gopherdata/gophernotes) 18 | 6. [GopherData-Github](https://github.com/gopherdata) 19 | 7. [GopherData-Website](gopherdata.github.io) 20 | 8. [Data Science Tools and libraries](https://github.com/gopherdata/resources/tree/master/tooling) 21 | 9. [Go Projects](https://github.com/golang/go/wiki/Projects) 22 | 10. [Go Commands](https://golang.org/cmd/go/) 23 | *** 24 | --------------------------------------------------------------------------------