Skip to content

Instantly share code, notes, and snippets.

@Elshaman
Created October 18, 2022 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elshaman/4ad9cfa656b850b3ccec36d1b69f0c90 to your computer and use it in GitHub Desktop.
Save Elshaman/4ad9cfa656b850b3ccec36d1b69f0c90 to your computer and use it in GitHub Desktop.
Golang: find a key in a map; key passed via command line
package main
import (
"fmt"
"os"
)
var persons map[string]string
func find(key string){
if val, ok := persons[key]; ok {
fmt.Println("Hi,",val)
}else{
fmt.Println("Sorry, not found")
}
}
func main(){
persons = make(map[string]string)
persons["305"] = "Sue"
persons["204"] = "Bob"
persons["631"] = "Jake"
persons["073"] = "Tracy"
key := os.Args[1]
find(key)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment