Skip to content

Commit

Permalink
refactor: 移除sonic,一个包加20M
Browse files Browse the repository at this point in the history
  • Loading branch information
liov committed Jun 26, 2024
1 parent 072fed6 commit e4275e9
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 276 deletions.
16 changes: 0 additions & 16 deletions utils/encoding/json/decode.go

This file was deleted.

16 changes: 0 additions & 16 deletions utils/encoding/json/decode_amd64.go

This file was deleted.

16 changes: 0 additions & 16 deletions utils/encoding/json/encode.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package iterator
//go:build amd64 && !sonic

package json

import (
jsoniter "github.com/json-iterator/go"
"github.com/json-iterator/go/extra"
"io"
)

var Standard = jsoniter.ConfigCompatibleWithStandardLibrary
Expand All @@ -11,14 +14,6 @@ func SupportPrivateFields() {
extra.SupportPrivateFields()
}

func Marshal(v interface{}) ([]byte, error) {
return Standard.Marshal(v)
}

func Unmarshal(data []byte, v interface{}) error {
return Standard.Unmarshal(data, v)
}

var WithPrivateField = jsoniter.Config{
IndentionStep: 4,
MarshalFloatWith6Digits: true,
Expand All @@ -27,3 +22,27 @@ var WithPrivateField = jsoniter.Config{
UseNumber: true,
ObjectFieldMustBeSimpleString: true,
}.Froze()

func NewEncoder(w io.Writer) *jsoniter.Encoder {
return Standard.NewEncoder(w)
}

func Marshal(v interface{}) ([]byte, error) {
return Standard.Marshal(v)
}

func MarshalString(v any) (string, error) {
return Standard.MarshalToString(v)
}

func NewDecoder(r io.Reader) *jsoniter.Decoder {
return Standard.NewDecoder(r)
}

func Unmarshal(data []byte, v any) error {
return jsoniter.ConfigDefault.Unmarshal(data, v)
}

func UnmarshalString(data string, v any) error {
return jsoniter.ConfigDefault.UnmarshalFromString(data, v)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build amd64
//go:build amd64 && snoic

package json

Expand All @@ -23,3 +23,19 @@ func MarshalReader(v interface{}) (io.Reader, error) {
}
return bytes.NewReader(data), nil
}

func MarshalString(v any) (string, error) {
return sonic.MarshalString(v)
}

func NewEncoder(w io.Writer) sonic.Encoder {
return sonic.ConfigDefault.NewEncoder(w)
}

func Unmarshal(data []byte, v any) error {
return sonic.Unmarshal(data, v)
}

func UnmarshalString(data string, v any) error {
return sonic.UnmarshalString(data, v)
}
11 changes: 0 additions & 11 deletions utils/encoding/json/sonic/sonic.go

This file was deleted.

14 changes: 5 additions & 9 deletions utils/net/http/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ import (
"net/http"
_ "net/http/pprof"
"runtime/debug"

"github.com/prometheus/client_golang/prometheus/promhttp"
)

func DebugHandler() http.Handler {
http.Handle("/debug/", http.HandlerFunc(Debug))
return http.DefaultServeMux
func StackHandler() http.Handler {
return http.HandlerFunc(Stack)
}

func Debug(w http.ResponseWriter, r *http.Request) {
func Stack(w http.ResponseWriter, r *http.Request) {
w.Write(debug.Stack())
}

func PromHandler() http.Handler {
http.Handle("/metrics", promhttp.Handler())
return http.DefaultServeMux
func init() {
http.Handle("/debug/", http.HandlerFunc(Stack))
}
2 changes: 1 addition & 1 deletion utils/net/http/gin/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func Debug(r *gin.Engine) {
r.Any("/debug/*path", Wrap(httpi.DebugHandler()))
r.Any("/debug/*path", Wrap(httpi.StackHandler()))
// Register Metrics metrics handler.
r.Any("/metrics", Wrap(promhttp.Handler()))
}
11 changes: 11 additions & 0 deletions utils/net/http/prometheus/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package prometheus

import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
)

func PromHandler() http.Handler {
http.Handle("/metrics", promhttp.Handler())
return http.DefaultServeMux
}
59 changes: 0 additions & 59 deletions utils/runtime/asm_amd64.s

This file was deleted.

9 changes: 0 additions & 9 deletions utils/runtime/asm_compat.s

This file was deleted.

126 changes: 0 additions & 126 deletions utils/runtime/gcwb.go

This file was deleted.

Loading

0 comments on commit e4275e9

Please sign in to comment.