controller.go 735 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. json2 "encoding/json"
  6. )
  7. // 替换encoding/json包
  8. type JsonStruct struct {
  9. }
  10. func (p *JsonStruct)MarshalToString(v interface{}) (string, error) {
  11. bytes, err := json2.Marshal(v)
  12. return string(bytes), err
  13. }
  14. func (p *JsonStruct)Marshal(v interface{}) ([]byte, error) {
  15. bytes, err := json2.Marshal(v)
  16. return bytes, err
  17. }
  18. func (p *JsonStruct)Unmarshal(bytes []byte, v interface{}) (error) {
  19. err := json2.Unmarshal(bytes, v)
  20. return err
  21. }
  22. var json = &JsonStruct{}
  23. // Controller
  24. type Controller struct {
  25. }
  26. // NewController return a new controller
  27. func NewController() *Controller {
  28. return &Controller{}
  29. }