beegoinit/response/json_test.go

38 lines
612 B
Go
Raw Normal View History

2020-07-10 10:51:40 +08:00
package response
import (
"bytes"
"encoding/json"
2020-07-10 10:51:40 +08:00
"fmt"
"testing"
)
type A struct {
Code int `json:"ret"`
Json
}
func (j *A) String() string {
s, _ := j.ToString()
return s
}
func (a *A) ToString() (str string, err error) {
var b []byte
b, err = json.Marshal(a)
return bytes.NewBuffer(b).String(), err
}
func (a *A) SetCode(code int) {
a.Code = code
}
2020-07-10 10:51:40 +08:00
func TestNewJsonByDefaultSuccess(t *testing.T) {
fmt.Println(NewJsonByDefaultSuccess())
}
func TestName(t *testing.T) {
resp := JsonResponseGenerator{&A{Code: 232}}
fmt.Println(fmt.Sprintf("%+v", resp.NewJonsByFailed(123232, "hahah")))
2020-07-10 10:51:40 +08:00
}