Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. )
  9.  
  10. //TimeData stores time in yyyy-mm-dd format
  11. type TimeData struct {
  12. Year int
  13. Month int
  14. Day int
  15. }
  16.  
  17. //ProdObjType describes Products data
  18. type ProdObjType struct {
  19. Attr string
  20. Type string
  21. Values []string
  22. }
  23.  
  24. //AttrObjType holds the different Attributes objects
  25. type AttrObjType struct {
  26. Attr string
  27. Type string
  28. TimeStamp []TimeData
  29. PriceRange []float64
  30. Descriptor []ProdObjType
  31. }
  32.  
  33. //JSONDescriptor holds the JSON data unmarshaled from the config.json
  34. type JSONDescriptor struct {
  35. Subject string
  36. Attributes []AttrObjType
  37. }
  38.  
  39.  
  40.  
  41. //GenerateSeedData generates seed data using the JSON Descriptor data
  42. func GenerateSeedData(n int) void {
  43.  
  44. }
  45.  
  46. func main() {
  47. file, jsonreaderror := ioutil.ReadFile("./newconfig.json")
  48. var jsonData JSONDescriptor
  49.  
  50. if jsonreaderror != nil {
  51. fmt.Printf("File error: %v \n", jsonreaderror)
  52. os.Exit(1)
  53. }
  54.  
  55. fmt.Println(file)
  56. fmt.Printf("%s \n", string(file))
  57.  
  58. json.Unmarshal(file, &jsonData)
  59. println(jsonData.Subject)
  60. for i := 0; i < len(jsonData.Attributes); i++ {
  61.  
  62. fmt.Println(jsonData.Attributes[i].Attr)
  63. fmt.Println(jsonData.Attributes[i].Type)
  64. fmt.Printf("TimeStamp size: %d \n", len(jsonData.Attributes[i].TimeStamp))
  65. for j := 0; j < len(jsonData.Attributes[i].TimeStamp); j++ {
  66. if j == 0 {
  67. fmt.Println("TimeStamp Data:")
  68. }
  69. fmt.Printf("\tYear:%d Month:%d Day:%d \n", jsonData.Attributes[i].TimeStamp[j].Year, jsonData.Attributes[i].TimeStamp[j].Month, jsonData.Attributes[i].TimeStamp[j].Day)
  70.  
  71. }
  72. for j := 0; j < len(jsonData.Attributes[i].PriceRange); j++ {
  73. if j == 0 {
  74. fmt.Println("Price Range:")
  75. }
  76. fmt.Printf("\t%f \n", jsonData.Attributes[i].PriceRange[j])
  77.  
  78. }
  79.  
  80. for j := 0; j < len(jsonData.Attributes[i].Descriptor); j++ {
  81. fmt.Printf("\tAttr: %s\n", jsonData.Attributes[i].Descriptor[j].Attr)
  82.  
  83. fmt.Printf("\tType: %s \n", jsonData.Attributes[i].Descriptor[j].Type)
  84.  
  85. for k := 0; k < len(jsonData.Attributes[i].Descriptor[j].Values); k++ {
  86. if k == 0 {
  87. fmt.Println("\t\tvalues:")
  88. }
  89. fmt.Printf("\t\t %s \n", jsonData.Attributes[i].Descriptor[j].Values[k])
  90. }
  91. }
  92. //fmt.Println(jsonData.Attributes[i].Descriptor[j].Attr)
  93.  
  94. }
  95.  
  96. GenerateSeedData(1000)
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement