Guest User

Untitled

a guest
Jul 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. package main
  2.  
  3. /*
  4. cat config.json
  5. {"object":
  6. {
  7. "buffer_size": 10,
  8. "Databases":
  9. [
  10. {
  11. "host": "localhost",
  12. "user": "root",
  13. "pass": "",
  14. "type": "mysql",
  15. "name": "go",
  16. "Tables":
  17. [
  18. {
  19. "name": "testing",
  20. "statment": "teststring",
  21. "regex": "teststring ([0-9]+) ([A-z]+)",
  22. "Types":
  23. [
  24. {
  25. "id": "int",
  26. "value": "string"
  27. }
  28. ]
  29. }
  30. ]
  31. }
  32. ]
  33. }
  34. }
  35.  
  36. */
  37.  
  38. import (
  39. "fmt"
  40. "os"
  41. "json"
  42. "io/ioutil"
  43. )
  44.  
  45. type jsonobject struct {
  46. Object ObjectType
  47. }
  48.  
  49. type ObjectType struct {
  50. Buffer_size int
  51. Databases []DatabasesType
  52. }
  53.  
  54. type DatabasesType struct {
  55. Host string
  56. User string
  57. Pass string
  58. Type string
  59. Name string
  60. Tables []TablesType
  61. }
  62.  
  63. type TablesType struct {
  64. Name string
  65. Statment string
  66. Regex string
  67. Types []TypesType
  68. }
  69.  
  70. type TypesType struct {
  71. Id string
  72. Value string
  73. }
  74.  
  75. // Main function
  76. // I realize this function is much too simple I am simply at a loss to
  77.  
  78. func main() {
  79. file, e := ioutil.ReadFile("./config.json")
  80. if e != nil {
  81. fmt.Printf("File error: %v\n", e)
  82. os.Exit(1)
  83. }
  84. fmt.Printf("%s\n", string(file))
  85.  
  86. //m := new(Dispatch)
  87. //var m interface{}
  88. var jsontype jsonobject
  89. json.Unmarshal(file, &jsontype)
  90. fmt.Printf("Results: %v\n", jsontype)
  91. }
Add Comment
Please, Sign In to add comment