mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Add an abstract json layout to make it's easier to change json library (#16528)
* Add an abstract json layout to make it's easier to change json library * Fix import * Fix import sequence * Fix blank lines * Fix blank lines
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
)
|
||||
|
||||
type connWriter struct {
|
||||
@@ -106,7 +106,6 @@ func NewConn() LoggerProvider {
|
||||
// Init inits connection writer with json config.
|
||||
// json config only need key "level".
|
||||
func (log *ConnLogger) Init(jsonconfig string) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal([]byte(jsonconfig), log)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse JSON: %v", err)
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
)
|
||||
|
||||
// CanColorStdout reports if we can color the Stdout
|
||||
@@ -52,7 +52,6 @@ func NewConsoleLogger() LoggerProvider {
|
||||
// Init inits connection writer with json config.
|
||||
// json config only need key "level".
|
||||
func (log *ConsoleLogger) Init(config string) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal([]byte(config), log)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse JSON: %v", err)
|
||||
|
@@ -15,8 +15,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// FileLogger implements LoggerProvider.
|
||||
@@ -101,7 +101,6 @@ func NewFileLogger() LoggerProvider {
|
||||
// "rotate":true
|
||||
// }
|
||||
func (log *FileLogger) Init(config string) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err := json.Unmarshal([]byte(config), log); err != nil {
|
||||
return fmt.Errorf("Unable to parse JSON: %v", err)
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
)
|
||||
|
||||
// Level is the level of the logger
|
||||
@@ -104,7 +104,6 @@ func FromString(level string) Level {
|
||||
// UnmarshalJSON takes text and turns it into a Level
|
||||
func (l *Level) UnmarshalJSON(b []byte) error {
|
||||
var tmp interface{}
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal(b, &tmp)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Err: %v", err)
|
||||
|
@@ -8,7 +8,8 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -17,7 +18,6 @@ type testLevel struct {
|
||||
}
|
||||
|
||||
func TestLevelMarshalUnmarshalJSON(t *testing.T) {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
levelBytes, err := json.Marshal(testLevel{
|
||||
Level: INFO,
|
||||
})
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
"net/smtp"
|
||||
"strings"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
)
|
||||
|
||||
type smtpWriter struct {
|
||||
@@ -57,7 +57,6 @@ func NewSMTPLogger() LoggerProvider {
|
||||
// "level":LevelError
|
||||
// }
|
||||
func (log *SMTPLogger) Init(jsonconfig string) error {
|
||||
json := jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
err := json.Unmarshal([]byte(jsonconfig), log)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse JSON: %v", err)
|
||||
|
Reference in New Issue
Block a user