github.com/rajeev159/opa@v0.45.0/topdown/type_name.go (about) 1 // Copyright 2018 The OPA Authors. All rights reserved. 2 // Use of this source code is governed by an Apache2 3 // license that can be found in the LICENSE file. 4 5 package topdown 6 7 import ( 8 "fmt" 9 10 "github.com/open-policy-agent/opa/ast" 11 ) 12 13 func builtinTypeName(a ast.Value) (ast.Value, error) { 14 switch a.(type) { 15 case ast.Null: 16 return ast.String("null"), nil 17 case ast.Boolean: 18 return ast.String("boolean"), nil 19 case ast.Number: 20 return ast.String("number"), nil 21 case ast.String: 22 return ast.String("string"), nil 23 case *ast.Array: 24 return ast.String("array"), nil 25 case ast.Object: 26 return ast.String("object"), nil 27 case ast.Set: 28 return ast.String("set"), nil 29 } 30 31 return nil, fmt.Errorf("illegal value") 32 } 33 34 func init() { 35 RegisterFunctionalBuiltin1(ast.TypeNameBuiltin.Name, builtinTypeName) 36 }