Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RodrigoMattosoSilveira/ca553c6a53ef800d5f5416aaaae7bd69 to your computer and use it in GitHub Desktop.
Save RodrigoMattosoSilveira/ca553c6a53ef800d5f5416aaaae7bd69 to your computer and use it in GitHub Desktop.
Convert GO: Convert a structure to a string
// GO: Convert a structure to a string
// Input: interface{}
// Output: (string, nil) if OK, ("", error) otherwise
//
func structToString (sourceStruct interface{}) (string, error) {
sourceJson, error := json.Marshal(sourceStruct)
if error != nil {
return "", error
}
return string(sourceJson), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment