Add with_std_json build tag

This commit is contained in:
世界
2022-07-24 17:58:52 +08:00
parent fe8e984608
commit 67edc163cb
17 changed files with 55 additions and 25 deletions

View File

@@ -3,9 +3,8 @@ package badjson
import (
"bytes"
"github.com/sagernet/sing-box/common/json"
E "github.com/sagernet/sing/common/exceptions"
"github.com/goccy/go-json"
)
type JSONArray[T any] []T

View File

@@ -1,9 +1,8 @@
package badjson
import (
"github.com/sagernet/sing-box/common/json"
E "github.com/sagernet/sing/common/exceptions"
"github.com/goccy/go-json"
)
func decodeJSON(decoder *json.Decoder) (any, error) {

View File

@@ -4,10 +4,9 @@ import (
"bytes"
"strings"
"github.com/sagernet/sing-box/common/json"
E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/x/linkedhashmap"
"github.com/goccy/go-json"
)
type JSONObject struct {

20
common/json/gojson.go Normal file
View File

@@ -0,0 +1,20 @@
//go:build !with_std_json
package json
import "github.com/goccy/go-json"
var (
Marshal = json.Marshal
Unmarshal = json.Unmarshal
NewEncoder = json.NewEncoder
NewDecoder = json.NewDecoder
)
type (
Encoder = json.Encoder
Decoder = json.Decoder
Token = json.Token
Delim = json.Delim
SyntaxError = json.SyntaxError
)

20
common/json/std.go Normal file
View File

@@ -0,0 +1,20 @@
//go:build with_std_json
package json
import "encoding/json"
var (
Marshal = json.Marshal
Unmarshal = json.Unmarshal
NewEncoder = json.NewEncoder
NewDecoder = json.NewDecoder
)
type (
Encoder = json.Encoder
Decoder = json.Decoder
Token = json.Token
Delim = json.Delim
SyntaxError = json.SyntaxError
)