Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Created October 24, 2016 09:09
Show Gist options
  • Save hsleonis/b2b43596bf36af2816296081523ff1aa to your computer and use it in GitHub Desktop.
Save hsleonis/b2b43596bf36af2816296081523ff1aa to your computer and use it in GitHub Desktop.
Variable and type in GoLang
package main
import (
"fmt"
)
func main(){
x,y:=3,4 // Assignment
x,y=y,x // Swap
a:=[]int{2,3,5} // Slice [Array]
b:=[]int{1}
m := map[string]int{"three": 3, "four": 4} // Map [Associative Array]
m["one"] = 1
_,_,_,_=x,y,a,b // Remove error if unused
b=append(b,a...) // Merge two slices
fmt.Println("Hello World!") // Print String
fmt.Println(sumProd(x,y)) // Print returned value from function
fmt.Println(b) // Print Array
fmt.Println(m["three"]) // Print from Map
}
func sumProd(x,y int)(sum, prod int){ // Arguments and return value
return x+y,x*y // Can return multiple values
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment