feat: add SerializerAdapter support custom serializer

This commit is contained in:
weloe
2023-05-17 01:16:14 +08:00
parent 900e86123a
commit 2d9f8124cc
5 changed files with 148 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
package util
import "fmt"
func HasNil(arr []interface{}) bool {
for _, elem := range arr {
if elem == nil {
@@ -17,3 +19,10 @@ func HasStr(arr []string, str string) bool {
}
return false
}
func InterfaceToBytes(data interface{}) ([]byte, error) {
if b, ok := data.([]byte); ok {
return b, nil
}
return nil, fmt.Errorf("unable to convert %T to []byte", data)
}