Skip to content

Commit a9f39fc

Browse files
committed
Adds short hand way to declare and initialize map
1 parent 0c33ce6 commit a9f39fc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

codes/ch5_maps/short-hand-way.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import "fmt";
4+
5+
func GetPrefix(name string) (prefix string) {
6+
7+
/**
8+
* Short hand way to declare and initialize map
9+
*/
10+
prefixMap := map[string] string {
11+
"Ashwin": "Sr. Fullstack Engineer",
12+
"Kumar": "Sr. Engineering Manager",
13+
"Saju": "Sr. Solution Architect",
14+
"Ajay": "Sr. Solution Architect", // comma is needed here
15+
}
16+
17+
return prefixMap[name]
18+
}
19+
20+
func main() {
21+
22+
fmt.Println("What is Ashwin's role? He is " + GetPrefix("Ashwin"))
23+
24+
}

0 commit comments

Comments
 (0)