Golang - gpawade/gpawade.github.io GitHub Wiki

Go Lang

Sample

	
	package main

	import (
		"fmt"
	)

	func main(){
		 fmt.Println("Entry point")
	}

Variable

  • 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

Basic Types

bool string

int int8 int16 int32 int64 uint uint8 uint32 uint32 uint64

byte //aliase for uint8 float32 float64 complex64 complex128

Type converstion

int(val) float64(val)

Global Variable

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"

	}

function

	
	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"
	}

Conditionals

if

Expression must be boolean.

if <boolean expression>{
	<code>
} else if <boolean expression>{
	<code>
}else {
	<code>
}

for

for i, val := range arrItems{
	<code>
}

for i < 40{
	<code>
}

for i:= 0; i < 10; i++{
	<code>
}

Struct

Concurrency

  • go routine
  • channer
⚠️ **GitHub.com Fallback** ⚠️