Like,other programming language each go program has a main function which is the entry point of the application.
import "fmt"
package main
func main(){
fmt.Println("Hello World")
}
in go we can define the variables with the var
keywords, we can define the variable with the multiple ways.
We can define the variable type explicitly with the var keywords.
var name string="Software Development with Golang"
If we have not defined the variable type it will implicitly define its type on variable initialization.
var age=12
here if we try to assign the string value to the age it will through the error because its type is int
implicitly declared while the varible is assigned.
we can declare variable with the short hand operators as well.so the basic sytax is as follows.
username,role,is_active:="kodega2016","software developer",true
another way to declare variables in Golang.
var (
company_name string="PortPro Nepal"
company_size int=100
company_address string="Sanepa,Nepal"
)
We can use if,else,if else for conditionals statement like other programming languages.
age:=10
if age<18{
fmt.Println("you are not allowed to visit this site.")
}
age:=18
if age<10{
fmt.Println("you are child")
}else if(age>10 && age<20){
fmt.Println("you are a teenager")
}else{
fmt.Println("you are a mature")
}
we can switch case for multiple conditionals checks.
role:="developer"
switch(role){
case "admin":
fmt.Println("you are an admin")
break;
case "developer":
fmt.Println("you are a developer")
break;
default:
fmt.Println("you are our guest")
}
In switch statement,there is a way t