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