Last active
June 1, 2017 14:24
-
-
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
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
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