Files

49 lines
981 B
Go
Raw Permalink Normal View History

2019-05-09 02:27:41 +03:00
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
2019-10-30 19:34:44 +03:00
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
2019-05-09 02:27:41 +03:00
package main
import (
"bufio"
"encoding/json"
"fmt"
"os"
)
type user struct {
Name string `json:"username"`
Permissions map[string]bool `json:"perms"`
}
func main() {
var input []byte
for in := bufio.NewScanner(os.Stdin); in.Scan(); {
input = append(input, in.Bytes()...)
}
var users []user
if err := json.Unmarshal(input, &users); err != nil {
fmt.Println(err)
return
}
for _, user := range users {
fmt.Print("+ ", user.Name)
switch p := user.Permissions; {
case p == nil:
fmt.Print(" has no power.")
case p["admin"]:
fmt.Print(" is an admin.")
case p["write"]:
fmt.Print(" can write.")
}
fmt.Println()
}
}