You could try a similar approach to the following one. I use it to put the language tags (en, es, pt…) in the predicate names, what was a problem that I found when using structs with the Golang Dgraph client.
One of my structs:
type Shop struct {
Uid string `json:"uid,omitempty"`
Document string `json:"shopDocument,omitempty"`
Name string `json:"shopName,omitempty"`
Image string `json:"shopImage,omitempty"`
Street *Street `json:"shopStreet,omitempty"`
Number string `json:"shopNumber,omitempty"`
Complement string `json:"shopComplement,omitempty"`
Location *Location `json:"shopLocation,omitempty"`
Prices []Price `json:"shopPrices,omitempty"`
}
My mutation method:
func MutateSet(structData interface{}, language string, fieldsWithLanguage []string) (map[string]string, error) {
mutation := api.Mutation{}
json, err := json.Marshal(structData)
if err != nil {
return nil, err
} else {
json = setLanguage(json, language, fieldsWithLanguage)
mutation.SetJson = json
return mutate(mutation)
}
}
The method I use to insert the language tag into the struct predicate:
func setLanguage(json []byte, language string, fieldsWithLanguage []string) []byte {
jsonAsString := string(json)
for _, fieldWithLanguage := range fieldsWithLanguage {
jsonAsString = strings.Replace(jsonAsString, fieldWithLanguage, fieldWithLanguage+"@"+language, -1)
}
json = []byte(jsonAsString)
return json
}
The process being executed:
var fieldsWithLanguage = []string{"shopName"}
var shop = Shop {/* some data */}
_, err := MutateSet(shop, "en", fieldsWithLanguage)
return err