Created
August 11, 2016 06:07
-
-
Save tkc/3616bed5da112eb7fd6c834beea47b48 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
) | |
type ( | |
user struct { | |
ID int `json:"id"` | |
Name string `json:"name"` | |
} | |
) | |
var ( | |
users = map[int]*user{} | |
) | |
func main() { | |
var map1 map[string]string = map[string]string{} | |
fmt.Println(map1) | |
//map[] | |
var map2 = make(map[string]string) | |
fmt.Println(map2) | |
//map[] | |
map3 := map[string]string{} | |
fmt.Println(map3) | |
//map[] | |
var map4 map[string]string = map[string]string{"one": "apple", "two": "orange"} | |
fmt.Println(map4) | |
//map[two:orange one:apple] | |
map5 := map[string]string{"one": "apple", "two": "orange"} | |
fmt.Println(map5) | |
//map[two:orange one:apple] | |
map6 := map[string]string{ | |
"one": "apple", | |
"two": "orange", | |
} | |
fmt.Println(map6) | |
//map[two:orange one:apple] | |
map7 := make(map[string]string) | |
map7["one"] = "apple" | |
map7["two"] = "orange" | |
fmt.Println(map7) | |
//map[two:orange one:apple] | |
map8 := map[int]string{ | |
1: "apple", | |
2: "orange", | |
} | |
fmt.Println(map8) | |
//map[1:apple 2:orange] | |
if val, ok := map8[1]; ok { | |
fmt.Printf("exists %#v", val) | |
} else { | |
fmt.Printf("not exists") | |
} | |
//exists "apple" | |
u := &user{ | |
ID: 1, | |
Name: "mike", | |
} | |
users[u.ID] = u | |
fmt.Println(users[1]) | |
//&{1 mike} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment