2023-12-22 13:20:45 +00:00
|
|
|
package dyn
|
2023-10-24 11:12:36 +00:00
|
|
|
|
2024-01-05 13:02:04 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
2023-10-24 11:12:36 +00:00
|
|
|
|
|
|
|
type Kind int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Invalid is the zero value of Kind.
|
|
|
|
KindInvalid Kind = iota
|
|
|
|
KindMap
|
|
|
|
KindSequence
|
|
|
|
KindString
|
|
|
|
KindBool
|
|
|
|
KindInt
|
|
|
|
KindFloat
|
|
|
|
KindTime
|
2024-01-05 13:02:04 +00:00
|
|
|
KindNil
|
2023-10-24 11:12:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func kindOf(v any) Kind {
|
|
|
|
switch v.(type) {
|
2024-03-25 11:01:09 +00:00
|
|
|
case Mapping:
|
2023-10-24 11:12:36 +00:00
|
|
|
return KindMap
|
|
|
|
case []Value:
|
|
|
|
return KindSequence
|
|
|
|
case string:
|
|
|
|
return KindString
|
|
|
|
case bool:
|
|
|
|
return KindBool
|
|
|
|
case int, int32, int64:
|
|
|
|
return KindInt
|
|
|
|
case float32, float64:
|
|
|
|
return KindFloat
|
|
|
|
case time.Time:
|
|
|
|
return KindTime
|
2024-01-05 13:02:04 +00:00
|
|
|
case nil:
|
|
|
|
return KindNil
|
2023-10-24 11:12:36 +00:00
|
|
|
default:
|
|
|
|
panic("not handled")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (k Kind) String() string {
|
|
|
|
switch k {
|
2024-01-05 13:02:04 +00:00
|
|
|
case KindInvalid:
|
|
|
|
return "invalid"
|
2023-10-24 11:12:36 +00:00
|
|
|
case KindMap:
|
|
|
|
return "map"
|
|
|
|
case KindSequence:
|
|
|
|
return "sequence"
|
|
|
|
case KindString:
|
|
|
|
return "string"
|
|
|
|
case KindBool:
|
|
|
|
return "bool"
|
|
|
|
case KindInt:
|
|
|
|
return "int"
|
|
|
|
case KindFloat:
|
|
|
|
return "float"
|
|
|
|
case KindTime:
|
|
|
|
return "time"
|
2024-01-05 13:02:04 +00:00
|
|
|
case KindNil:
|
|
|
|
return "nil"
|
2023-10-24 11:12:36 +00:00
|
|
|
default:
|
2024-01-05 13:02:04 +00:00
|
|
|
panic(fmt.Sprintf("invalid kind value: %d", k))
|
2023-10-24 11:12:36 +00:00
|
|
|
}
|
|
|
|
}
|