Exemple #1
0
// SetHeader should receive a flat struct with no nested types. It will also overwrite existing headers.
func (t *Client) SetHeader(h interface{}) error {
	m := structs.Map(h)
	for k, v := range m {
		if structs.IsStruct(v) {
			return errors.New("Field of struct is a struct.  Can't set header value to a whole struct")
		}
		str := fmt.Sprintf("%v", v)
		t.Headers[k] = []string{str}
	}
	return nil
}
Exemple #2
0
// CheckData - checks the validity of config data. Data sould be of type struct and contain a string type field called "Version"
func CheckData(data interface{}) error {
	if !structs.IsStruct(data) {
		return iodine.New(errors.New("Invalid argument type. Expecing \"struct\" type."), nil)
	}

	st := structs.New(data)
	f, ok := st.FieldOk("Version")
	if !ok {
		return iodine.New(fmt.Errorf("Invalid type of struct argument. No [%s.Version] field found.", st.Name()), nil)
	}

	if f.Kind() != reflect.String {
		return iodine.New(fmt.Errorf("Invalid type of struct argument. Expecting \"string\" type [%s.Version] field.", st.Name()), nil)
	}

	return nil
}
Exemple #3
0
// Create a new Map value from a structure.  Error returned if argument is not a structure
// or if there is a json.Marshal or json.Unmarshal error.
//	Only public structure fields are decoded in the Map value. Also, json.Marshal structure encoding rules
//	are followed for decoding the structure fields.
func NewMapStruct(structVal interface{}) (Map, error) {
	if !structs.IsStruct(structVal) {
		return nil, errors.New("NewMapStruct() error: argument is not type Struct")
	}
	return structs.Map(structVal), nil
}