Closed godcong closed 5 years ago
I looked into this, the issue is not caused by any of the recent changes.
As a workaround, I renamed elements named child, to child1 and child2 and this is the output I got:
type AutoGenerated struct {
Mounts []struct {
Child1 struct {
Path string `json:"path"`
ShardFunc string `json:"shardFunc"`
Sync bool `json:"sync"`
Type string `json:"type"`
} `json:"child1,omitempty"`
Mountpoint string `json:"mountpoint"`
Prefix string `json:"prefix"`
Type string `json:"type"`
Child2 struct {
Compression string `json:"compression"`
Path string `json:"path"`
Type string `json:"type"`
} `json:"child2,omitempty"`
} `json:"mounts"`
Type string `json:"type"`
}
@mahdi-hosseini I'm going to send you an invite to be a collaborator on this project, that way you can have rights to merge PRs into master and even update gh-pages without having to wait for me. :+1:
@mholt Awesome, thanks! The goal is to segue to maintaining caddy 😛
This is resolved. Make sure to hard refresh or use your browser's private/incognito mode to see the changes.
yes,i tried it.
the result has two child struct:
type AutoGenerated struct {
Mounts []struct {
Child struct {
Path string `json:"path"`
ShardFunc string `json:"shardFunc"`
Sync bool `json:"sync"`
Type string `json:"type"`
} `json:"child,omitempty"`
Mountpoint string `json:"mountpoint"`
Prefix string `json:"prefix"`
Type string `json:"type"`
Child struct {
Compression string `json:"compression"`
Path string `json:"path"`
Type string `json:"type"`
} `json:"child,omitempty"`
} `json:"mounts"`
Type string `json:"type"`
}
i think the correct is like this:
type AutoGenerated struct {
Mounts []struct {
Child struct {
Path string `json:"path,omitempty"`
ShardFunc string `json:"shardFunc,omitempty"`
Sync bool `json:"sync,omitempty"`
Type string `json:"type,omitempty"`
Compression string `json:"compression,omitempty"`
} `json:"child"`
Mountpoint string `json:"mountpoint"`
Prefix string `json:"prefix"`
Type string `json:"type"`
} `json:"mounts"`
Type string `json:"type"`
}
@godcong That's by design. I wanted to leave the decision of combining the two structs to the Go developer. In general JSONs can have arbitrary type of data in them. A generalization like that comes with assumptions and trade-offs.
@mholt Please let me know if you have a different take on my response.
for example: { "mounts": [ { "child": { "path": "blocks", "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2", "sync": true, "type": "flatfs" }, "mountpoint": "/blocks", "prefix": "flatfs.datastore", "type": "measure" }, { "child": { "compression": "none", "path": "datastore", "type": "levelds" }, "mountpoint": "/", "prefix": "leveldb.datastore", "type": "measure" } ], "type": "mount" }
parsed struct: type AutoGenerated struct { Mounts []struct { Child struct { Path
json:"path"
ShardFuncjson:"shardFunc"
Syncjson:"sync"
Typejson:"type"
}json:"child"
Mountpointjson:"mountpoint"
Prefixjson:"prefix"
Typejson:"type"
}json:"mounts"
Type stringjson:"type"
}the second child's element
compression
was missed