如何在 Go 中为以下数据结构创建 struct
?
{
"description": String,
"public": Boolean,
"files": {
"some_filename.txt": {
"contents": String
}
}
}
我从以下开始:
type File struct {
// stuck here?
}
type Payload struct {
Description string
Public bool
Files File
}
非常感谢将此用于 HTTP post 请求的任何帮助。
最佳答案
当 key 在编译时未知时使用映射:
type File struct {
Contents string
}
type Payload struct {
Description string
Public bool
Files map[string]*File
}
关于http - 使用计算键去构造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47482278/