Skip to content

Instantly share code, notes, and snippets.

@yangsibai
Last active January 15, 2016 08:15
Show Gist options
  • Save yangsibai/c6a95f355e3ce101d4c2 to your computer and use it in GitHub Desktop.
Save yangsibai/c6a95f355e3ce101d4c2 to your computer and use it in GitHub Desktop.
{
"Users": ["UserA","UserB"],
"Groups": ["GroupA"]
}
import (
"encoding/json"
"os"
"fmt"
)
type Configuration struct {
Users []string
Groups []string
}
file, _ := os.Open("conf.json")
decoder := json.NewDecoder(file)
configuration := Configuration{}
err := decoder.Decode(&configuration)
if err != nil {
fmt.Println("error:", err)
}
fmt.Println(configuration.Users) // output: [UserA, UserB]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment