controller.go 841 B

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