统一初始beego mvc 的方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
612 B

  1. package response
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "testing"
  7. )
  8. type A struct {
  9. Code int `json:"ret"`
  10. Json
  11. }
  12. func (j *A) String() string {
  13. s, _ := j.ToString()
  14. return s
  15. }
  16. func (a *A) ToString() (str string, err error) {
  17. var b []byte
  18. b, err = json.Marshal(a)
  19. return bytes.NewBuffer(b).String(), err
  20. }
  21. func (a *A) SetCode(code int) {
  22. a.Code = code
  23. }
  24. func TestNewJsonByDefaultSuccess(t *testing.T) {
  25. fmt.Println(NewJsonByDefaultSuccess())
  26. }
  27. func TestName(t *testing.T) {
  28. resp := JsonResponseGenerator{&A{Code: 232}}
  29. fmt.Println(fmt.Sprintf("%+v", resp.NewJonsByFailed(123232, "hahah")))
  30. }