* fix proto codec
pull/709/head
Tony Chen 4 years ago committed by GitHub
parent cdcc6e40a5
commit f50b731aa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      README.md
  2. 5
      config/config.go
  3. 7
      config/reader.go

@ -2,8 +2,8 @@
[![Language](https://img.shields.io/badge/Language-Go-blue.svg)](https://golang.org/) [![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) [![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) [![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)](https://goreportcard.com/report/github.com/go-kratos/kratos) [![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) [![Discord](https://img.shields.io/discord/766619759214854164?label=chat&logo=discord)](https://discord.gg/BWzJsUJ)
# Kratos # Kratos
@ -48,9 +48,9 @@ Kratos 一套轻量级 Go 微服务框架,包含大量微服务相关框架及
### Install Kratos ### Install Kratos
``` ```
# 安装生成工具 # 安装生成工具
go get github.com/go-kratos/kratos/cmd/kratos go get github.com/go-kratos/kratos/cmd/kratos/v2
go get github.com/go-kratos/kratos/cmd/protoc-gen-go-http 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 go get github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2
# 或者通过 Source 安装 # 或者通过 Source 安装
cd cmd/kratos && go install cd cmd/kratos && go install

@ -7,6 +7,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/go-kratos/kratos/v2/encoding"
"github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/log"
) )
@ -17,6 +18,8 @@ var (
ErrTypeAssert = errors.New("type assert error") ErrTypeAssert = errors.New("type assert error")
_ Config = (*config)(nil) _ Config = (*config)(nil)
codec = encoding.GetCodec("json")
) )
// Observer is config observer. // Observer is config observer.
@ -120,7 +123,7 @@ func (c *config) Scan(v interface{}) error {
if err != nil { if err != nil {
return err return err
} }
return json.Unmarshal(data, v) return codec.Unmarshal(data, v)
} }
func (c *config) Watch(key string, o Observer) error { func (c *config) Watch(key string, o Observer) error {

@ -1,7 +1,6 @@
package config package config
import ( import (
"encoding/json"
"fmt" "fmt"
"strings" "strings"
@ -72,16 +71,16 @@ func (r *reader) Value(path string) (Value, bool) {
} }
func (r *reader) Source() ([]byte, error) { 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) { func cloneMap(src map[string]interface{}) (map[string]interface{}, error) {
data, err := json.Marshal(src) data, err := codec.Marshal(src)
if err != nil { if err != nil {
return nil, err return nil, err
} }
dst := make(map[string]interface{}) 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 nil, err
} }
return dst, nil return dst, nil

Loading…
Cancel
Save