Files
buildx/vendor/github.com/open-policy-agent/opa/v1/ast/strings.go
T
Sebastiaan van Stijn c74f522b8e vendor: github.com/open-policy-agent/opa v1.14.1
updating to the lowest minor release that contains [opa@e9ca3ed], which removed
some redundant imports that resulted in indirect dependencies.

full diff: https://github.com/open-policy-agent/opa/compare/v1.10.1...v1.14.1

[opa@e9ca3ed]: https://github.com/open-policy-agent/opa/commit/e9ca3ed4151e5f1850b379aa62cad77669f453a5

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-07-01 15:31:34 +02:00

57 lines
1.2 KiB
Go

// Copyright 2016 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.
package ast
import (
"reflect"
"strings"
)
// TypeName returns a human readable name for the AST element type.
func TypeName(x any) string {
if _, ok := x.(*lazyObj); ok {
return "object"
}
return strings.ToLower(reflect.Indirect(reflect.ValueOf(x)).Type().Name())
}
// ValueName returns a human readable name for the AST Value type.
// This is preferrable over calling TypeName when the argument is known to be
// a Value, as this doesn't require reflection (= heap allocations).
func ValueName(x Value) string {
switch x.(type) {
case String:
return "string"
case Boolean:
return "boolean"
case Number:
return "number"
case Null:
return "null"
case Var:
return "var"
case Object:
return "object"
case Set:
return "set"
case Ref:
return "ref"
case Call:
return "call"
case *Array:
return "array"
case *ArrayComprehension:
return "arraycomprehension"
case *ObjectComprehension:
return "objectcomprehension"
case *SetComprehension:
return "setcomprehension"
case *TemplateString:
return "templatestring"
}
return TypeName(x)
}