在 Go 中表示 JSON 策略
我想生成此 JSON 策略:
{"Statement":[{"Resource":"RESOURCE","Condition":{"DateLessThan":{"AWS:EpochTime":EXPIRES}}}]}
下面显示的解决方案会生成以下 JSON:
{"Statement":{"Resource":"example.com","Condition":{"DateLessThan":{"AWS:EpochTime":"1234543"}}}}
如何更改此设置以使“Statement”:具有数组值?
package main
import (
"json"
"fmt"
)
type S struct {
Statement Statement
}
type Statement struct {
Resource string
Condition Date
}
type Date struct {
DateLessThan AWS
}
type AWS struct {
EpochTime string "AWS:EpochTime"
}
func main() {
expires := "1234543"
resource := "example.com"
date := &AWS{EpochTime: expires}
date2 := &Date{DateLessThan:*date}
reso := &Statement{Resource: resource, Condition: *date2}
statement := &S{Statement: *reso}
result1, _ := json.Marshal(statement)
fmt.Printf(result1)
}
I would like to Generate this JSON policy:
{"Statement":[{"Resource":"RESOURCE","Condition":{"DateLessThan":{"AWS:EpochTime":EXPIRES}}}]}
The solution I'm showing below produces the following JSON:
{"Statement":{"Resource":"example.com","Condition":{"DateLessThan":{"AWS:EpochTime":"1234543"}}}}
How do I change this so that "Statement": has an array value?
package main
import (
"json"
"fmt"
)
type S struct {
Statement Statement
}
type Statement struct {
Resource string
Condition Date
}
type Date struct {
DateLessThan AWS
}
type AWS struct {
EpochTime string "AWS:EpochTime"
}
func main() {
expires := "1234543"
resource := "example.com"
date := &AWS{EpochTime: expires}
date2 := &Date{DateLessThan:*date}
reso := &Statement{Resource: resource, Condition: *date2}
statement := &S{Statement: *reso}
result1, _ := json.Marshal(statement)
fmt.Printf(result1)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应用以下更改:
希望这应该清楚地表明:您需要一个 Statement 对象的切片,而不仅仅是一个单独的 Statement。
Apply the following changes:
Hopefully that should make it clear: you want a slice of Statement objects, rather than just a single Statement.