Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
466 B

  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. )
  6. func getPassedArgs() string {
  7. if len(os.Args) != 2 {
  8. fmt.Printf("Exactly 1 argument is needed\n")
  9. os.Exit(1)
  10. }
  11. return os.Args[1]
  12. }
  13. func main() {
  14. m := map[string]string{
  15. "305": "Sue",
  16. "204": "Bob",
  17. "631": "Jake",
  18. "073": "Tracy",
  19. }
  20. key := getPassedArgs()
  21. if name := m[key]; name != "" {
  22. fmt.Println("Hi,", name)
  23. } else {
  24. fmt.Println(key, "not found")
  25. os.Exit(1)
  26. }
  27. }