Fix iri collection marshaling

This commit is contained in:
Marius Orcsik 2019-12-19 21:03:31 +01:00
parent 147cc84d20
commit b973dafdba
No known key found for this signature in database
GPG key ID: 889CE8E4FB2D877A

8
iri.go
View file

@ -94,16 +94,14 @@ func (i IRIs) MarshalJSON() ([]byte, error) {
if len(i) == 0 {
return nil, nil
}
notEmpty := false
writeComma := func() { writeS(&b, ",") }
writeCommaIfNotEmpty := func(notEmpty bool) {
if notEmpty {
writeComma()
writeS(&b, ",")
}
}
write(&b, '[')
for _, iri := range i {
writeCommaIfNotEmpty(notEmpty)
for k, iri := range i {
writeCommaIfNotEmpty(k > 0)
write(&b, '"')
writeS(&b, iri.String())
write(&b, '"')