diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 102e0c0d5..b1e35bb35 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -24,11 +24,6 @@ jobs: - name: Test run: go test -v ./... - - name: Lint - run: | - go get golang.org/x/lint/golint - golint ./... - - name: Kratos run: | cd cmd/kratos @@ -52,3 +47,8 @@ jobs: cd examples go build ./... go test ./... + + - name: Lint + run: | + go get golang.org/x/lint/golint + golint ./... diff --git a/encoding/xml/xml.go b/encoding/xml/xml.go new file mode 100644 index 000000000..1876039bf --- /dev/null +++ b/encoding/xml/xml.go @@ -0,0 +1,37 @@ +package xml + +import ( + "encoding/xml" + "reflect" + + "github.com/go-kratos/kratos/v2/encoding" +) + +// Name is the name registered for the xml codec. +const Name = "xml" + +func init() { + encoding.RegisterCodec(codec{}) +} + +// codec is a Codec implementation with xml. +type codec struct{} + +func (codec) Marshal(v interface{}) ([]byte, error) { + return xml.Marshal(v) +} + +func (codec) Unmarshal(data []byte, v interface{}) error { + rv := reflect.ValueOf(v) + for rv.Kind() == reflect.Ptr { + if rv.IsNil() { + rv.Set(reflect.New(rv.Type().Elem())) + } + rv = rv.Elem() + } + return xml.Unmarshal(data, v) +} + +func (codec) Name() string { + return Name +} diff --git a/transport/transport.go b/transport/transport.go index 91ba7d48d..b268aaefa 100644 --- a/transport/transport.go +++ b/transport/transport.go @@ -6,6 +6,7 @@ import ( // init encoding _ "github.com/go-kratos/kratos/v2/encoding/json" _ "github.com/go-kratos/kratos/v2/encoding/proto" + _ "github.com/go-kratos/kratos/v2/encoding/xml" ) // Server is transport server.