Skip to content

Commit

Permalink
Merge pull request #21 from hegdeashwin/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Ashwin Hegde committed Jun 27, 2015
2 parents f94e051 + 2697eb4 commit 2544b69
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
21 changes: 21 additions & 0 deletions codes/ch5_maps/create-a-map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

/**
* Note: The code will not run and throw an error: prefixMap declared and not used
* As we have declare map and not used in and this is error in go-lang
*/
func main() {

/**
* Declare a map of map type with string.
* var <variable-name> map[<key-type>] <value-type>
*/
var prefixMap map[string] string

/**
* make will initialize the map; if we don't use make
* declaration will set to null;
*/
prefixMap = make(map[string] string)

}
39 changes: 39 additions & 0 deletions codes/ch5_maps/delete-into-a-map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import "fmt";

func GetPrefix(name string, mustDel bool) (prefix string) {

/**
* Short hand way to declare and initialize map
*/
prefixMap := map[string] string {
"Ashwin": "Sr. Fullstack Engineer",
"Kumar": "Sr. Engineering Manager",
"Saju": "Sr. Solution Architect",
"Ajay": "Sr. Solution Architect", // comma is needed here
}

if mustDel {
/**
* Old way to perform delete operation on map.
* Will no more work for new version of Go compiler
*/
// prefixMap["Saju"] = "", false

/**
* New way to perform delete operation on map.
*/
delete(prefixMap, "Saju")
}

return prefixMap[name]
}

func main() {

fmt.Println("What is Saju's role? He is " + GetPrefix("Saju", false))

fmt.Println("What is Saju's role? He is " + GetPrefix("Saju", true))

}
27 changes: 27 additions & 0 deletions codes/ch5_maps/insert-into-a-map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import "fmt";

func GetPrefix(name string) (prefix string) {

var prefixMap map[string] string
prefixMap = make(map[string] string)

/**
* Insert key and value into the map.
*
* <map-variable>[<key>] = <value>
*/
prefixMap["Ashwin"] = "Sr. Fullstack Engineer"
prefixMap["Kumar"] = "Sr. Engineering Manager"
prefixMap["Saju"] = "Sr. Solution Architect"
prefixMap["Ajay"] = "Sr. solution Architect"

return prefixMap[name]
}

func main() {

fmt.Println("What is Ashwin's role? He is " + GetPrefix("Ashwin"))

}
24 changes: 24 additions & 0 deletions codes/ch5_maps/short-hand-way.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import "fmt";

func GetPrefix(name string) (prefix string) {

/**
* Short hand way to declare and initialize map
*/
prefixMap := map[string] string {
"Ashwin": "Sr. Fullstack Engineer",
"Kumar": "Sr. Engineering Manager",
"Saju": "Sr. Solution Architect",
"Ajay": "Sr. Solution Architect", // comma is needed here
}

return prefixMap[name]
}

func main() {

fmt.Println("What is Ashwin's role? He is " + GetPrefix("Ashwin"))

}
31 changes: 31 additions & 0 deletions codes/ch5_maps/update-into-a-map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import "fmt";

func GetPrefix(name string) (prefix string) {

/**
* Short hand way to declare and initialize map
*/
prefixMap := map[string] string {
"Ashwin": "Sr. Fullstack Engineer",
"Kumar": "Sr. Engineering Manager",
"Saju": "Sr. Solution Architect",
"Ajay": "Sr. Solution Architect", // comma is needed here
}

/**
* Perform update operation on map.
*/
prefixMap["Kumar"] = "Delivery Manager"
prefixMap["Ajay"] = "Sr. Project Manager"

return prefixMap[name]
}

func main() {

fmt.Println("What is Kumar's role? He is " + GetPrefix("Kumar"))
fmt.Println("What is Ajay's role? He is " + GetPrefix("Ajay"))

}
Empty file removed codes/session-5/.gitkeep
Empty file.

0 comments on commit 2544b69

Please sign in to comment.