forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_name.go
36 lines (30 loc) · 808 Bytes
/
type_name.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2018 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 topdown
import (
"fmt"
"github.com/open-policy-agent/opa/ast"
)
func builtinTypeName(a ast.Value) (ast.Value, error) {
switch a.(type) {
case ast.Null:
return ast.String("null"), nil
case ast.Boolean:
return ast.String("boolean"), nil
case ast.Number:
return ast.String("number"), nil
case ast.String:
return ast.String("string"), nil
case ast.Array:
return ast.String("array"), nil
case ast.Object:
return ast.String("object"), nil
case ast.Set:
return ast.String("set"), nil
}
return nil, fmt.Errorf("illegal value")
}
func init() {
RegisterFunctionalBuiltin1(ast.TypeNameBuiltin.Name, builtinTypeName)
}