Skip to content

Instantly share code, notes, and snippets.

@esell
Created May 19, 2017 20:24
Show Gist options
  • Save esell/2c280ab1efae37e0b4d87f40d81381b5 to your computer and use it in GitHub Desktop.
Save esell/2c280ab1efae37e0b4d87f40d81381b5 to your computer and use it in GitHub Desktop.
type MyTemplate struct {
ContentVersion string `json:"contentVersion"`
// Resources could be other types outside of Resource1, hence the []string
Resources []string `json:"resources"`
}
type Resource1 struct {
ResourceType string `json:"-"`
APIVersion string `json:"apiVersion"`
Comments string `json:"comments"`
Type string `json:"type"`
}
var Resources = make(map[string]Resource1)
finalTemplate := MyTemplate{ContentVersion: "1.0.0.0"}
for k, v := range Resources {
if len(k) > 1 {
blah, err := json.Marshal(v)
if err != nil {
}
finalTemplate.Resources = append(finalTemplate.Resources, string(blah))
}
}
finalBlah, err := json.Marshal(finalTemplate)
if err != nil {
}
fmt.Printf("%s\n", finalBlah)
// CURRENT OUTPUT
{
"$schema":"",
"contentVersion":"1.0.0.0",
"resources":[
"{ ///// Notice the quote?
\"apiVersion\":\"\",
\"comments\":\"\",
\"type\":\"Microsoft.Network/virtualNetworks\"
}" ///// Notice the quote?
]
}
// EXPECTED OUTPUT
// OUTPUT
{
"$schema":"",
"contentVersion":"1.0.0.0",
"resources":[
{
\"apiVersion\":\"\",
\"comments\":\"\",
\"type\":\"Microsoft.Network/virtualNetworks\"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment