Add with_std_json build tag

This commit is contained in:
世界 2022-07-24 17:58:52 +08:00
parent fe8e984608
commit 67edc163cb
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
17 changed files with 55 additions and 25 deletions

View File

@ -5,10 +5,10 @@ import (
"os"
"github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/common/json"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/goccy/go-json"
"github.com/spf13/cobra"
)

View File

@ -5,10 +5,10 @@ import (
"os"
"path/filepath"
"github.com/sagernet/sing-box/common/json"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/goccy/go-json"
"github.com/spf13/cobra"
)

View File

@ -7,10 +7,10 @@ import (
"syscall"
"github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/common/json"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/goccy/go-json"
"github.com/spf13/cobra"
)

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
)

View File

@ -2,11 +2,11 @@ package clashapi
import (
"bytes"
"encoding/json"
"net/http"
"strconv"
"time"
"github.com/sagernet/sing-box/common/json"
"github.com/sagernet/sing-box/experimental/clashapi/trafficontrol"
"github.com/go-chi/chi/v5"

View File

@ -11,6 +11,7 @@ import (
"time"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/json"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/experimental/clashapi/trafficontrol"
"github.com/sagernet/sing-box/log"
@ -22,7 +23,6 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
"github.com/go-chi/render"
"github.com/goccy/go-json"
"github.com/gorilla/websocket"
)

View File

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

View File

@ -1,11 +1,10 @@
package option
import (
"github.com/sagernet/sing-box/common/json"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
"github.com/goccy/go-json"
)
type DNSOptions struct {

View File

@ -1,12 +1,11 @@
package option
import (
"github.com/sagernet/sing-box/common/json"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/auth"
E "github.com/sagernet/sing/common/exceptions"
"github.com/goccy/go-json"
)
type _Inbound struct {

View File

@ -4,10 +4,9 @@ import (
"bytes"
"github.com/sagernet/sing-box/common/badjson"
"github.com/sagernet/sing-box/common/json"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
"github.com/goccy/go-json"
)
func ToMap(v any) (*badjson.JSONObject, error) {

View File

@ -1,12 +1,11 @@
package option
import (
"github.com/sagernet/sing-box/common/json"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
"github.com/goccy/go-json"
)
type _Outbound struct {

View File

@ -1,11 +1,10 @@
package option
import (
"github.com/sagernet/sing-box/common/json"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
"github.com/goccy/go-json"
)
type RouteOptions struct {

View File

@ -5,11 +5,10 @@ import (
"strings"
"time"
"github.com/sagernet/sing-box/common/json"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-dns"
E "github.com/sagernet/sing/common/exceptions"
"github.com/goccy/go-json"
)
type ListenAddress netip.Addr