Last active
June 12, 2024 00:32
-
-
Save RodrigoMattosoSilveira/ca553c6a53ef800d5f5416aaaae7bd69 to your computer and use it in GitHub Desktop.
Convert GO: Convert a structure to a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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