mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-19 15:01:22 +02:00
feat: custom json marshaler implementation
This commit is contained in:
18
pkg/json/map_slice.go
Normal file
18
pkg/json/map_slice.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package json
|
||||
|
||||
type MapSlice[V any] []Map[V]
|
||||
|
||||
func (s MapSlice[V]) MarshalJSONTo(buf []byte) []byte {
|
||||
buf = append(buf, '[')
|
||||
i := 0
|
||||
n := len(s)
|
||||
for _, entry := range s {
|
||||
buf = entry.MarshalJSONTo(buf)
|
||||
if i != n-1 {
|
||||
buf = append(buf, ',')
|
||||
}
|
||||
i++
|
||||
}
|
||||
buf = append(buf, ']')
|
||||
return buf
|
||||
}
|
||||
Reference in New Issue
Block a user