Skip to content

nsit-karan/go-essentials

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-essentials

go quick rampup

module1 notes

  • function overloading is not allowed in go (method overloading is allowed though)
    • implies that i cant have 2 functions with same name and diff return types
  • go follows pass by value, i.e, a copy is passed to the function
  • go slices and arrays

go maps

Ways to initialize the map (var m map[int] string <<---- declare the map)

  1. Use make. Eg: maps1 := make(map[int] string) maps1[0] = "stone"

  2. Use map literal map2 := map[int] string { 1: "stone", 2: "gold", 3: "silver" }

    This can also be used to intialize an empty map as well map3 := map[int] string {}

module1 build

  • Till the code was organized into folders but was not using go modules (go.mod), simpl 'go build' works - go build -o bin/module1 module1/*.go
  • now, with the code organized as go modules, the way to run the code is:
    • navigate to module1
    • go run main.go

module2 notes

structs

consider a ptr to a named struct 'person, i.e, 'var ptr *person = ....'. go allowed to access the variables of person directly using '.' operator, i.e, ptr.name, ptr.age work fine. These are equivalent to (*ptr).name, (*ptr).age. This is the 'syntactic sugar' that go allows while accessing fields of a named struct when given a pointer to the named struct

Good references

About

go quick rampup

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages