-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from hegdeashwin/develop
Develop
- Loading branch information
Showing
6 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.