dal/pkg/filters/utils.go

30 lines
392 B
Go
Raw Normal View History

package filters
import (
"encoding/json"
)
2024-08-08 17:26:29 +00:00
func FromJson[T IFilter](data interface{}) *T {
var t T
str, ok := data.(string)
if ok {
err := json.Unmarshal([]byte(str), &t)
if err != nil {
2024-08-08 17:26:29 +00:00
return &t
}
}
2024-08-08 17:26:29 +00:00
m, ok := data.(Filter)
if ok {
s, err := json.Marshal(m)
if err != nil {
2024-08-08 17:26:29 +00:00
return &t
}
e := json.Unmarshal(s, &t)
if e != nil {
2024-08-08 17:26:29 +00:00
return &t
}
}
return &t
}