李伟乐 2 years ago
parent d7abadee25
commit 454acc373c
  1. 19
      encoding/xml/xml_test.go
  2. 5
      transport/http/codec.go

@ -0,0 +1,19 @@
package xml
import (
"fmt"
"testing"
)
type Map struct {
Use int
A string
}
func TestEncode(t *testing.T) {
c := codec{}
fmt.Println(c.Marshal(Map{
Use: 11,
A: "xxx",
}))
}

@ -57,7 +57,6 @@ func DefaultRequestDecoder(r *http.Request, v any) error {
return nil
}
func DefaultResponseEncoder(w http.ResponseWriter, r *http.Request, v any) error {
fmt.Println("DefaultResponseEncoder")
if v == nil {
return nil
}
@ -76,12 +75,8 @@ func DefaultResponseEncoder(w http.ResponseWriter, r *http.Request, v any) error
return err
}
func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err error) {
fmt.Println("DefaultErrorEncoder")
se := errors.FromError(err)
codec, _ := CodeForRequest(r, "Accept")
codec = encoding.GetCodec("xml")
fmt.Println(codec.Name())
fmt.Printf("%+v\n", se)
body, err := codec.Marshal(se)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)

Loading…
Cancel
Save