anilist/utils.go
2023-10-09 13:49:37 +02:00

25 lines
460 B
Go

package anilist
import (
"reflect"
"time"
)
func addValue2InterfaceMap[K, T comparable](m map[K]interface{}, key K, value T) {
if value != *new(T) {
if reflect.TypeOf(new(T)).Elem() == reflect.TypeOf(new(time.Time)).Elem() {
var t interface{} = value
m[key] = t.(time.Time).Unix()
return
}
m[key] = value
}
}
func addSlice2InterfaceMap[K, T comparable](m map[K]interface{}, key K, value []T) {
if len(value) > 0 {
m[key] = value
}
}