I'm trying to split a comma separated string and use the values to initalize a struct. This is how I do it right now:
type Address struct {
Street string
City string
ZipCode string
}
s := strings.Split("street,city,zip", ",")
data := Address{Street: s[0], City: s[1], ZipCode: s[2]}
The problem I'm having is that I have to handle this input as well:
"street,"
"street,city"
Any idea how to do it without going out of range? I've looked into unpacking with triple dots syntax ... but structs does not seem to support it.
len(s)to ensure you don't index out of bounds.