diff --git a/README.md b/README.md index dd0d781ad..53232f6b7 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![Language](https://img.shields.io/badge/Language-Go-blue.svg)](https://golang.org/) [![Build Status](https://github.com/go-kratos/kratos/workflows/Go/badge.svg)](https://github.com/go-kratos/kratos/actions) -[![GoDoc](https://godoc.org/github.com/go-kratos/kratos?status.svg)](https://godoc.org/github.com/go-kratos/kratos) -[![Go Report Card](https://goreportcard.com/badge/github.com/go-kratos/kratos)](https://goreportcard.com/report/github.com/go-kratos/kratos) +[![GoDoc](https://pkg.go.dev/badge/github.com/go-kratos/kratos/v2)](https://pkg.go.dev/github.com/go-kratos/kratos/v2) +[![Go Report Card](https://goreportcard.com/badge/github.com/go-kratos/kratos/v2)](https://goreportcard.com/report/github.com/go-kratos/kratos/v2) [![Discord](https://img.shields.io/discord/766619759214854164?label=chat&logo=discord)](https://discord.gg/BWzJsUJ) # Kratos @@ -48,9 +48,9 @@ Kratos 一套轻量级 Go 微服务框架,包含大量微服务相关框架及 ### Install Kratos ``` # 安装生成工具 -go get github.com/go-kratos/kratos/cmd/kratos -go get github.com/go-kratos/kratos/cmd/protoc-gen-go-http -go get github.com/go-kratos/kratos/cmd/protoc-gen-go-errors +go get github.com/go-kratos/kratos/cmd/kratos/v2 +go get github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2 +go get github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2 # 或者通过 Source 安装 cd cmd/kratos && go install diff --git a/config/config.go b/config/config.go index 15ef8e678..cf3f07d34 100644 --- a/config/config.go +++ b/config/config.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "github.com/go-kratos/kratos/v2/encoding" "github.com/go-kratos/kratos/v2/log" ) @@ -17,6 +18,8 @@ var ( ErrTypeAssert = errors.New("type assert error") _ Config = (*config)(nil) + + codec = encoding.GetCodec("json") ) // Observer is config observer. @@ -120,7 +123,7 @@ func (c *config) Scan(v interface{}) error { if err != nil { return err } - return json.Unmarshal(data, v) + return codec.Unmarshal(data, v) } func (c *config) Watch(key string, o Observer) error { diff --git a/config/reader.go b/config/reader.go index de6c24bc5..601557eeb 100644 --- a/config/reader.go +++ b/config/reader.go @@ -1,7 +1,6 @@ package config import ( - "encoding/json" "fmt" "strings" @@ -72,16 +71,16 @@ func (r *reader) Value(path string) (Value, bool) { } func (r *reader) Source() ([]byte, error) { - return json.Marshal(r.values) + return codec.Marshal(r.values) } func cloneMap(src map[string]interface{}) (map[string]interface{}, error) { - data, err := json.Marshal(src) + data, err := codec.Marshal(src) if err != nil { return nil, err } dst := make(map[string]interface{}) - if err = json.Unmarshal(data, &dst); err != nil { + if err = codec.Unmarshal(data, &dst); err != nil { return nil, err } return dst, nil