func setValue(fv *reflect.Value, c *Config, key string) error {
	switch fv.Kind() {
	case reflect.Int:
		val, err := c.GetInt(key)
		if err != nil {
			return err
		}
		fv.SetInt(int64(val))
	case reflect.Float64:
		val, err := c.GetFloat(key)
		if err != nil {
			return err
		}
		fv.SetFloat(val)
	case reflect.Bool:
		val, err := c.GetBool(key)
		if err != nil {
			return err
		}
		fv.SetBool(val)
	case reflect.String:
		val, err := c.GetString(key)
		if err != nil {
			return err
		}
		fv.SetString(val)
	}
	return nil
}
setValue updates the field value in fv to the data extracted from config
with key.
package cfg
import (
	"bytes"
	"errors"
	"fmt"
	"reflect"
)
const tagKey = "cfg"
func Unmarshal(data []byte, v interface{}) error {
	buf := bytes.NewBuffer(data)
	c, err := NewConfigFromReader(buf)
	if err != nil {
		return fmt.Errorf("cfg: error parsing data %s", err)
	}
	return UnmarshalFromConfig(c, v)
}
func UnmarshalFromConfig(c *Config, v interface{}) error {
	rv := reflect.ValueOf(v)
	if rv.Kind() != reflect.Ptr || rv.Elem().Kind() != reflect.Struct {
		return errors.New("cfg: interface must be a pointer to struct")
	}
	rv = rv.Elem()
	for i := 0; i < rv.NumField(); i++ {
		fv := rv.Field(i)         
		sf := rv.Type().Field(i)  
		if sf.PkgPath != "" {  
			continue
		}
		tag := sf.Tag.Get(tagKey)
		if tag == "-" {
			continue
		}
		for key := range c.values {
			if key != tag && bytes.EqualFold([]byte(key), []byte(sf.Name)) == false {
				continue
			}
			err := setValue(&fv, c, key)
			if err != nil {
				return fmt.Errorf("cfg: error setting field value: %s", err)
			}
		}
	}
	return nil
}