deps: Update github.com/hashicorp/hil/...
This commit is contained in:
parent
49995428fd
commit
819bd3fba3
|
@ -1,3 +0,0 @@
|
|||
.DS_Store
|
||||
.idea
|
||||
*.iml
|
|
@ -1,3 +0,0 @@
|
|||
sudo: false
|
||||
language: go
|
||||
go: 1.5
|
|
@ -2,14 +2,48 @@ package hil
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/hashicorp/hil/ast"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
var hilMapstructureDecodeHookSlice []interface{}
|
||||
var hilMapstructureDecodeHookStringSlice []string
|
||||
var hilMapstructureDecodeHookMap map[string]interface{}
|
||||
|
||||
// hilMapstructureWeakDecode behaves in the same way as mapstructure.WeakDecode
|
||||
// but has a DecodeHook which defeats the backward compatibility mode of mapstructure
|
||||
// which WeakDecodes []interface{}{} into an empty map[string]interface{}. This
|
||||
// allows us to use WeakDecode (desirable), but not fail on empty lists.
|
||||
func hilMapstructureWeakDecode(m interface{}, rawVal interface{}) error {
|
||||
config := &mapstructure.DecoderConfig{
|
||||
DecodeHook: func(source reflect.Type, target reflect.Type, val interface{}) (interface{}, error) {
|
||||
sliceType := reflect.TypeOf(hilMapstructureDecodeHookSlice)
|
||||
stringSliceType := reflect.TypeOf(hilMapstructureDecodeHookStringSlice)
|
||||
mapType := reflect.TypeOf(hilMapstructureDecodeHookMap)
|
||||
|
||||
if (source == sliceType || source == stringSliceType) && target == mapType {
|
||||
return nil, fmt.Errorf("Cannot convert %s into a %s", source, target)
|
||||
}
|
||||
|
||||
return val, nil
|
||||
},
|
||||
WeaklyTypedInput: true,
|
||||
Result: rawVal,
|
||||
}
|
||||
|
||||
decoder, err := mapstructure.NewDecoder(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return decoder.Decode(m)
|
||||
}
|
||||
|
||||
func InterfaceToVariable(input interface{}) (ast.Variable, error) {
|
||||
var stringVal string
|
||||
if err := mapstructure.WeakDecode(input, &stringVal); err == nil {
|
||||
if err := hilMapstructureWeakDecode(input, &stringVal); err == nil {
|
||||
return ast.Variable{
|
||||
Type: ast.TypeString,
|
||||
Value: stringVal,
|
||||
|
@ -17,7 +51,7 @@ func InterfaceToVariable(input interface{}) (ast.Variable, error) {
|
|||
}
|
||||
|
||||
var mapVal map[string]interface{}
|
||||
if err := mapstructure.WeakDecode(input, &mapVal); err == nil {
|
||||
if err := hilMapstructureWeakDecode(input, &mapVal); err == nil {
|
||||
elements := make(map[string]ast.Variable)
|
||||
for i, element := range mapVal {
|
||||
varElement, err := InterfaceToVariable(element)
|
||||
|
@ -34,7 +68,7 @@ func InterfaceToVariable(input interface{}) (ast.Variable, error) {
|
|||
}
|
||||
|
||||
var sliceVal []interface{}
|
||||
if err := mapstructure.WeakDecode(input, &sliceVal); err == nil {
|
||||
if err := hilMapstructureWeakDecode(input, &sliceVal); err == nil {
|
||||
elements := make([]ast.Variable, len(sliceVal))
|
||||
for i, element := range sliceVal {
|
||||
varElement, err := InterfaceToVariable(element)
|
||||
|
|
|
@ -836,12 +836,16 @@
|
|||
"revisionTime": "2016-06-07T00:19:40Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "rYMJhG5J/OzcBIRfatklb/+JrJ4=",
|
||||
"path": "github.com/hashicorp/hil",
|
||||
"revision": "01dc167cd239b7ccab78a683b866536cd5904719"
|
||||
"revision": "58c35af3b2c3a72c572851bc9e650b62a61d5ec2",
|
||||
"revisionTime": "2016-06-05T07:46:40Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "eJv3RKa2gk/4khPzo3+pJzThz8w=",
|
||||
"path": "github.com/hashicorp/hil/ast",
|
||||
"revision": "01dc167cd239b7ccab78a683b866536cd5904719"
|
||||
"revision": "42cfb33535beaca9a8ca2ef415930a1bd8f32998",
|
||||
"revisionTime": "2016-06-03T20:14:09Z"
|
||||
},
|
||||
{
|
||||
"path": "github.com/hashicorp/logutils",
|
||||
|
|
Loading…
Reference in New Issue