|
- package response
-
- import (
- "bytes"
- "encoding/json"
- "fmt"
- "testing"
- )
-
- type A struct {
- Code int `json:"ret"`
- Json
- }
-
- func (j *A) GetDefaultSuccessCode() int {
- return 0
- }
-
- func (j *A) GetDefaultFailedCode() int {
- return -1
- }
-
- func (j *A) String() string {
- b, err := json.Marshal(j)
- if err == nil {
- return bytes.NewBuffer(b).String()
- }
- return ""
- }
-
- func (a *A) SetCode(code int) {
- a.Code = code
- }
-
- func TestNewJsonByDefaultSuccess(t *testing.T) {
- fmt.Println(NewJsonByDefaultSuccess())
- }
-
- func TestName(t *testing.T) {
- resp := JsonResponseGenerator{&A{Code: 232}}
- fmt.Println(fmt.Sprintf("%+v", resp.NewJsonByDefaultFailed()))
- }
|