Guest User

Untitled

a guest
Nov 20th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. type Config struct {
  2. Server struct {
  3. Host string `json:"host"`
  4. Port string `json:"port"`
  5. } `json:"server"`
  6. Postgres struct {
  7. Host string `json:"host"`
  8. User string `json:"user"`
  9. Password string `json:"password"`
  10. DB string `json:"db"`
  11. } `json:"database"`
  12. }
  13.  
  14. func main() {
  15. jsonConfig := []byte(`{
  16. "server":{
  17. "host":"localhost",
  18. "port":"8080"},
  19. "database":{
  20. "host":"localhost",
  21. "user":"db_user",
  22. "password":"supersecret",
  23. "db":"my_db"}}`)
  24. var config Config
  25. err := json.Unmarshal(jsonConfig, &config)
  26. if err != nil {
  27. panic(err)
  28. }
  29. fmt.Printf("Config: %+v\n", config)
  30. }
Add Comment
Please, Sign In to add comment