另客网go项目公用的代码库

unit.go 326B

123456789101112131415161718192021
  1. package utils
  2. import (
  3. "encoding/json"
  4. )
  5. // 去掉struct的空字段
  6. func Struct2Slimming(input interface{}) (interface{}, error) {
  7. bs, err := json.Marshal(input)
  8. if err != nil {
  9. return nil, err
  10. }
  11. var output interface{}
  12. if err = json.Unmarshal(bs, &output); err != nil {
  13. return nil, err
  14. }
  15. return output, nil
  16. }