-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathvalue.go
More file actions
34 lines (28 loc) · 741 Bytes
/
value.go
File metadata and controls
34 lines (28 loc) · 741 Bytes
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
package expression
import (
"go.yaml.in/yaml/v4"
)
// ValueOrExpression represents a raw value or expression in the Arazzo document.
type ValueOrExpression = *yaml.Node
// GetValueOrExpressionValue will return the value or expression from the provided ValueOrExpression.
func GetValueOrExpressionValue(value ValueOrExpression) (*yaml.Node, *Expression, error) {
if value == nil {
return nil, nil, nil
}
if value.Kind == yaml.ScalarNode {
var val any
if err := value.Decode(&val); err != nil {
return nil, nil, err
}
switch v := val.(type) {
case string:
asExpression := Expression(v)
if asExpression.IsExpression() {
return nil, &asExpression, nil
}
default:
break
}
}
return value, nil, nil
}