Support for DynamicValue inline rendering.

Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
Dave Shanley
2023-04-22 06:25:40 -04:00
parent 10374e801b
commit 9edb995d12
2 changed files with 182 additions and 137 deletions

View File

@@ -76,3 +76,43 @@ func (d *DynamicValue[A, B]) MarshalYAML() (interface{}, error) {
}
return &n, err
}
// MarshalYAML will create a ready to render YAML representation of the DynamicValue object.
func (d *DynamicValue[A, B]) MarshalYAMLInline() (interface{}, error) {
// this is a custom renderer, we can't use the NodeBuilder out of the gate.
var n yaml.Node
var err error
var value any
if d.IsA() {
value = d.A
}
if d.IsB() {
value = d.B
}
to := reflect.TypeOf(value)
switch to.Kind() {
case reflect.Ptr:
if r, ok := value.(high.RenderableInline); ok {
return r.MarshalYAMLInline()
} else {
_ = n.Encode(value)
}
case reflect.Bool:
_ = n.Encode(value.(bool))
case reflect.Int:
_ = n.Encode(value.(int))
case reflect.String:
_ = n.Encode(value.(string))
case reflect.Int64:
_ = n.Encode(value.(int64))
case reflect.Float64:
_ = n.Encode(value.(float64))
case reflect.Float32:
_ = n.Encode(value.(float32))
case reflect.Int32:
_ = n.Encode(value.(int32))
}
return &n, err
}

View File

@@ -76,6 +76,11 @@ func (r *Responses) FindResponseByCode(code int) *Response {
return r.Codes[fmt.Sprintf("%d", code)]
}
// GetDefaultResponse will
func (r *Responses) GetDefaultResponse(code int) *Response {
return r.Codes[fmt.Sprintf("%d", code)]
}
// GoLow returns the low-level Response object used to create the high-level one.
func (r *Responses) GoLow() *low.Responses {
return r.low