Skip to content

Commit

Permalink
Disable bytedance/sonic on go1.21 (#8)
Browse files Browse the repository at this point in the history
* internal/json: disable bytedance/sonic on go1.21

* zapcl: move SetEscapeHTML to internal/json

* codecov: ignore internal/json coverage

---------

Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
  • Loading branch information
zchee authored Mar 29, 2023
1 parent d7ae568 commit 62fe3a4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/.codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ coverage:

ignore:
- "caller.go"
- "internal/json"

comment:
layout: "newheader, diff, flags, files"
Expand Down
21 changes: 21 additions & 0 deletions internal/json/encoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2023 The zapcl Authors
// SPDX-License-Identifier: BSD-3-Clause

//go:build arm64 || (go1.21 && amd64)
// +build arm64 go1.21,amd64

package json

import (
"io"

gojson "github.com/goccy/go-json"
"go.uber.org/zap/zapcore"
)

// NewEncoder returns the github.com/goccy/go-json NewEncoder.
func NewEncoder(w io.Writer) zapcore.ReflectedEncoder {
enc := gojson.NewEncoder(w)
enc.SetEscapeHTML(false)
return enc
}
13 changes: 10 additions & 3 deletions internal/json/encoder_amd64.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
// Copyright 2023 The zapcl Authors
// SPDX-License-Identifier: BSD-3-Clause

//go:build !go1.21 && amd64
// +build !go1.21,amd64

package json

import (
"io"

"github.com/bytedance/sonic/encoder"
"github.com/bytedance/sonic"
"go.uber.org/zap/zapcore"
)

// NewEncoder returns the new bytedance/sonic/encoder.StreamEncoder.
func NewEncoder(w io.Writer) *encoder.StreamEncoder {
return encoder.NewStreamEncoder(w)
func NewEncoder(w io.Writer) zapcore.ReflectedEncoder {
enc := sonic.ConfigFastest.NewEncoder(w)
enc.SetEscapeHTML(false)

return enc
}
15 changes: 0 additions & 15 deletions internal/json/encoder_arm64.go

This file was deleted.

4 changes: 1 addition & 3 deletions zapcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ func NewEncoderConfig() zapcore.EncoderConfig {
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
NewReflectedEncoder: func(w io.Writer) zapcore.ReflectedEncoder {
enc := json.NewEncoder(w)
enc.SetEscapeHTML(false)
return enc
return json.NewEncoder(w)
},
}
}
Expand Down

0 comments on commit 62fe3a4

Please # to comment.