Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "fmt"
- "io/ioutil"
- "os"
- )
- //TimeData stores time in yyyy-mm-dd format
- type TimeData struct {
- Year int
- Month int
- Day int
- }
- //ProdObjType describes Products data
- type ProdObjType struct {
- Attr string
- Type string
- Values []string
- }
- //AttrObjType holds the different Attributes objects
- type AttrObjType struct {
- Attr string
- Type string
- TimeStamp []TimeData
- PriceRange []float64
- Descriptor []ProdObjType
- }
- //JSONDescriptor holds the JSON data unmarshaled from the config.json
- type JSONDescriptor struct {
- Subject string
- Attributes []AttrObjType
- }
- //GenerateSeedData generates seed data using the JSON Descriptor data
- func GenerateSeedData(n int) void {
- }
- func main() {
- file, jsonreaderror := ioutil.ReadFile("./newconfig.json")
- var jsonData JSONDescriptor
- if jsonreaderror != nil {
- fmt.Printf("File error: %v \n", jsonreaderror)
- os.Exit(1)
- }
- fmt.Println(file)
- fmt.Printf("%s \n", string(file))
- json.Unmarshal(file, &jsonData)
- println(jsonData.Subject)
- for i := 0; i < len(jsonData.Attributes); i++ {
- fmt.Println(jsonData.Attributes[i].Attr)
- fmt.Println(jsonData.Attributes[i].Type)
- fmt.Printf("TimeStamp size: %d \n", len(jsonData.Attributes[i].TimeStamp))
- for j := 0; j < len(jsonData.Attributes[i].TimeStamp); j++ {
- if j == 0 {
- fmt.Println("TimeStamp Data:")
- }
- 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)
- }
- for j := 0; j < len(jsonData.Attributes[i].PriceRange); j++ {
- if j == 0 {
- fmt.Println("Price Range:")
- }
- fmt.Printf("\t%f \n", jsonData.Attributes[i].PriceRange[j])
- }
- for j := 0; j < len(jsonData.Attributes[i].Descriptor); j++ {
- fmt.Printf("\tAttr: %s\n", jsonData.Attributes[i].Descriptor[j].Attr)
- fmt.Printf("\tType: %s \n", jsonData.Attributes[i].Descriptor[j].Type)
- for k := 0; k < len(jsonData.Attributes[i].Descriptor[j].Values); k++ {
- if k == 0 {
- fmt.Println("\t\tvalues:")
- }
- fmt.Printf("\t\t %s \n", jsonData.Attributes[i].Descriptor[j].Values[k])
- }
- }
- //fmt.Println(jsonData.Attributes[i].Descriptor[j].Attr)
- }
- GenerateSeedData(1000)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement