File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
examples/gocollective/check-if-map-contains-key Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ version : ' 3'
2+
3+ tasks :
4+ imports :
5+ cmds :
6+ - goimports -w .
7+ vet :
8+ cmds :
9+ - go vet .
10+ run :
11+ cmds :
12+ - go run -race main.go
Original file line number Diff line number Diff line change 1+ // Stackoverflow Go Collective example
2+ //
3+ // How to check if a map contains a key in Go?
4+ //
5+ // URL
6+ // - https://stackoverflow.com/questions/2050391/how-to-check-if-a-map-contains-a-key-in-go
7+ //
8+ // REFERENCES
9+ package main
10+
11+ import "fmt"
12+
13+ func main () {
14+ // Goでmapに対象のキーがあるのかを確認するのは以下のようにする
15+
16+ var (
17+ m = make (map [string ]string )
18+ )
19+ m ["hello" ] = "world"
20+
21+ v , ok := m ["hello" ]
22+ if ! ok {
23+ fmt .Printf ("key '%s' does not exists." , "hello" )
24+ }
25+ fmt .Println (v )
26+
27+ v , ok = m ["world" ]
28+ if ! ok {
29+ fmt .Printf ("key '%s' does not exists." , "world" )
30+ }
31+ fmt .Println (v )
32+ }
You can’t perform that action at this time.
0 commit comments