mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-22 17:19:06 +01:00
feat: custom json marshaling implementation, replace json and yaml library (#89)
* chore: replace gopkg.in/yaml.v3 vs goccy/go-yaml; replace encoding/json with bytedance/sonic * fix: yaml unmarshal panic * feat: custom json marshaler implementation * chore: fix import and err marshal handling --------- Co-authored-by: yusing <yusing@6uo.me>
This commit is contained in:
24
pkg/json/map.go
Normal file
24
pkg/json/map.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type Map[V any] map[string]V
|
||||
|
||||
func (m Map[V]) MarshalJSONTo(buf []byte) []byte {
|
||||
buf = append(buf, '{')
|
||||
i := 0
|
||||
n := len(m)
|
||||
for k, v := range m {
|
||||
buf = AppendString(buf, k)
|
||||
buf = append(buf, ':')
|
||||
buf = appendMarshal(reflect.ValueOf(v), buf)
|
||||
if i != n-1 {
|
||||
buf = append(buf, ',')
|
||||
}
|
||||
i++
|
||||
}
|
||||
buf = append(buf, '}')
|
||||
return buf
|
||||
}
|
||||
Reference in New Issue
Block a user