广告平台(站长使用)
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.

serialize.go 382 B

4 kuukautta sitten
1234567891011121314151617181920212223
  1. package utils
  2. import (
  3. "encoding/json"
  4. )
  5. func Serialize(data interface{}) []byte {
  6. res, err := json.Marshal(data)
  7. if err != nil {
  8. return []byte{}
  9. }
  10. return res
  11. }
  12. func Unserialize(b []byte, dst interface{}) {
  13. if err := json.Unmarshal(b, dst); err != nil {
  14. dst = nil
  15. }
  16. }
  17. func SerializeStr(data interface{}, arg ...interface{}) string {
  18. return string(Serialize(data))
  19. }