Golang - gpawade/gpawade.github.io GitHub Wiki
package main
import (
"fmt"
)
func main(){
fmt.Println("Entry point")
}
- Uninitialized variable get
zero
value - Package level variable are
global
- Package level variable must be declare with
var
- Declare function variable with
:=
- Go passes argument by value
bool string
int int8 int16 int32 int64 uint uint8 uint32 uint32 uint64
byte //aliase for uint8 float32 float64 complex64 complex128
int(val) float64(val)
4
package main
var(
name = "Ganesh"
param2 string = "some value"
)
const (
PI = 3.14
)
func main(){
// function variable declaration
a := "some value"
b string := "some value"
}
func <func Name> (param String) <returnType>{
<code>
}
func titleCase (text string) string{
return "some string"
}
// function return multiple values
func testFun()(string, string){
return "one", "two"
}
Expression must be boolean
.
if <boolean expression>{
<code>
} else if <boolean expression>{
<code>
}else {
<code>
}
for i, val := range arrItems{
<code>
}
for i < 40{
<code>
}
for i:= 0; i < 10; i++{
<code>
}
- go routine
- channer