Skip to content

Instantly share code, notes, and snippets.

@crgimenes
Last active June 1, 2017 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crgimenes/73033b74571a3f0c23713f80d5d533ec to your computer and use it in GitHub Desktop.
Save crgimenes/73033b74571a3f0c23713f80d5d533ec to your computer and use it in GitHub Desktop.
Experimental function to parse array/slice to string compatible with array of postgresql
func parseArray(value interface{}) string {
switch value.(type) {
case []interface{}:
var aux string
for _, v := range value.([]interface{}) {
if aux != "" {
aux += ","
}
aux += parseArray(v)
}
return "{" + aux + "}"
case string:
aux := value.(string)
aux = strings.Replace(aux, `\`, `\\`, -1)
aux = strings.Replace(aux, `"`, `\"`, -1)
return `"` + aux + `"`
case int:
return strconv.Itoa(value.(int))
}
return ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment