Advertisement
cwchen

[Go] Check the existence of some key in map.

Sep 23rd, 2017
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.38 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "log"
  5. )
  6.  
  7. func main() {
  8.     m := make(map[string]string)
  9.  
  10.     m["Go"] = "Beego"
  11.     m["Python"] = "Django"
  12.     m["Ruby"] = "Rails"
  13.     m["PHP"] = "Laravel"
  14.  
  15.     v, ok := m["Go"]
  16.     if !ok {
  17.         log.Fatal("It should be true")
  18.     }
  19.  
  20.     if !(v == "Beego") {
  21.         log.Fatal("Wrong value")
  22.     }
  23.  
  24.     _, ok = m["Java"]
  25.     if !(ok == false) {
  26.         log.Fatal("It should be false")
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement