reflect.go 548 B

12345678910111213141516171819202122232425262728
  1. package sprig
  2. import (
  3. "fmt"
  4. "reflect"
  5. )
  6. // typeIs returns true if the src is the type named in target.
  7. func typeIs(target string, src interface{}) bool {
  8. return target == typeOf(src)
  9. }
  10. func typeIsLike(target string, src interface{}) bool {
  11. t := typeOf(src)
  12. return target == t || "*"+target == t
  13. }
  14. func typeOf(src interface{}) string {
  15. return fmt.Sprintf("%T", src)
  16. }
  17. func kindIs(target string, src interface{}) bool {
  18. return target == kindOf(src)
  19. }
  20. func kindOf(src interface{}) string {
  21. return reflect.ValueOf(src).Kind().String()
  22. }