Guest User

Untitled

a guest
Aug 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "log"
  8. )
  9.  
  10. type ObjectType struct {
  11. Database DatabasesType
  12. }
  13.  
  14. type DatabasesType struct {
  15. Type string
  16. Host string
  17. Username string
  18. Password string
  19. }
  20.  
  21. func main() {
  22. file, e := ioutil.ReadFile("./configuration.json")
  23. if e != nil {
  24. panic(e)
  25. }
  26. fmt.Printf("%s\n", string(file))
  27.  
  28. var dbType ObjectType
  29. err := json.Unmarshal(file, &dbType)
  30. if err != nil {
  31. log.Println(err)
  32. }
  33. fmt.Printf("type : %s\n", dbType.Database.Type)
  34. fmt.Printf("host : %s\n", dbType.Database.Host)
  35. fmt.Printf("username : %s\n", dbType.Database.Username)
  36. fmt.Printf("password : %s\n", dbType.Database.Password)
  37. }
Add Comment
Please, Sign In to add comment