I am trying to change the policy for an s3 bucket on aws. I have created the following json structure for a policy:
type Policy struct {
Version string `json:"Version"`
Id string `json:"Id"`
Statement []Statement `json:"Statement"`
}
type Statement struct {
Sid string `json:"Sid"`
Effect string `json:"Effect"`
Principal Principal `json:"Principal"`
Action []string `json:"Action"`
Resource []string `json:"Resource"`
}
type Principal struct {
AWS[]string `json:"AWS"`
}
Which works fine for putting bucket policies in place. The issue comes when I try to get the current policy and modify it.
If there is a statement that only has one AWS, Action, or Resource value, Amazon will convert it from an array to a simple value, causing my unmarshalling to fail.
Is there any way that I can specify AWS/Action/Resource values to be either a string slice or just a string?
I know that there are packages available that I could use to get around this to some extent (github.com/Jeffail/gabs
, for example), but it would be cleaner to just create the JSON structure since it is fairly simple.