mini.go
func (config *Config) DataFromSection(sectionName string, data interface{}) bool {
	section := config.sectionForName(sectionName)

	if section == nil {
		return false
	}

	values := section.values

	fields := reflect.ValueOf(data).Elem()
	dataType := fields.Type()

	for i := 0; i < fields.NumField(); i++ {
		field := fields.Field(i)

		if !field.CanSet() {
			continue
		}

		fieldType := dataType.Field(i)
		fieldName := fieldType.Name

		switch field.Type().Kind() {
		case reflect.Bool:
			field.SetBool(getBoolean(values, fieldName, field.Interface().(bool)))
		case reflect.Int64:
			field.SetInt(getInteger(values, fieldName, field.Interface().(int64)))
		case reflect.Float64:
			field.SetFloat(getFloat(values, fieldName, field.Interface().(float64)))
		case reflect.String:
			field.SetString(getString(values, fieldName, field.Interface().(string)))
		case reflect.Array, reflect.Slice:
			switch fieldType.Type.Elem().Kind() {
			case reflect.Int64:
				ints := getIntegers(values, fieldName)
				if ints != nil {
					field.Set(reflect.ValueOf(ints))
				}
			case reflect.Float64:
				floats := getFloats(values, fieldName)
				if floats != nil {
					field.Set(reflect.ValueOf(floats))
				}
			case reflect.String:
				strings := getStrings(values, fieldName)
				if strings != nil {
					field.Set(reflect.ValueOf(strings))
				}
			}
		}
	}
	return true
}
func (config *Config) DataFromSection(sectionName string, data interface{}) bool {
	section := config.sectionForName(sectionName)

	if section == nil {
		return false
	}

	values := section.values

	fields := reflect.ValueOf(data).Elem()
	dataType := fields.Type()

	for i := 0; i < fields.NumField(); i++ {
		field := fields.Field(i)

		if !field.CanSet() {
			continue
		}

		fieldType := dataType.Field(i)
		fieldName := fieldType.Name

		switch field.Type().Kind() {
		case reflect.Bool:
			field.SetBool(getBoolean(values, fieldName, field.Interface().(bool)))
		case reflect.Int64:
			field.SetInt(getInteger(values, fieldName, field.Interface().(int64)))
		case reflect.Float64:
			field.SetFloat(getFloat(values, fieldName, field.Interface().(float64)))
		case reflect.String:
			field.SetString(getString(values, fieldName, field.Interface().(string)))
		case reflect.Array, reflect.Slice:
			switch fieldType.Type.Elem().Kind() {
			case reflect.Int64:
				ints := getIntegers(values, fieldName)
				if ints != nil {
					field.Set(reflect.ValueOf(ints))
				}
			case reflect.Float64:
				floats := getFloats(values, fieldName)
				if floats != nil {
					field.Set(reflect.ValueOf(floats))
				}
			case reflect.String:
				strings := getStrings(values, fieldName)
				if strings != nil {
					field.Set(reflect.ValueOf(strings))
				}
			}
		}
	}
	return true
}
func ( config * Config ) DataFromSection ( sectionName string , data interface { } ) bool { section := config . sectionForName ( sectionName ) if section == nil { return false } values := section . values fields := reflect . ValueOf ( data ) . Elem ( ) dataType := fields . Type ( ) for i := 0 ; i < fields . NumField ( ) ; i ++ { field := fields . Field ( i ) if ! field . CanSet ( ) { continue } fieldType := dataType . Field ( i ) fieldName := fieldType . Name switch field . Type ( ) . Kind ( ) { case reflect . Bool : field . SetBool ( getBoolean ( values , fieldName , field . Interface ( ) . ( bool ) ) ) case reflect . Int64 : field . SetInt ( getInteger ( values , fieldName , field . Interface ( ) . ( int64 ) ) ) case reflect . Float64 : field . SetFloat ( getFloat ( values , fieldName , field . Interface ( ) . ( float64 ) ) ) case reflect . String : field . SetString ( getString ( values , fieldName , field . Interface ( ) . ( string ) ) ) case reflect . Array , reflect . Slice : switch fieldType . Type . Elem ( ) . Kind ( ) { case reflect . Int64 : ints := getIntegers ( values , fieldName ) if ints != nil { field . Set ( reflect . ValueOf ( ints ) ) } case reflect . Float64 : floats := getFloats ( values , fieldName ) if floats != nil { field . Set ( reflect . ValueOf ( floats ) ) } case reflect . String : strings := getStrings ( values , fieldName ) if strings != nil { field . Set ( reflect . ValueOf ( strings ) ) } } } } return true }
/*
DataFromSection reads the values of a section into a struct. The values should be of the types:
  bool
  string
  []string
  int64
  []int64
  float64
  []float64
Values that are missing in the section are not set, and values that are missing in the
struct but present in the section are ignored.

If the section name matches the config.name or "" the global data is searched.
*/
/ * DataFromSection reads the values of a section into a struct . The values should be of the types : bool string [] string int64 [] int64 float64 [] float64 Values that are missing in the section are not set and values that are missing in the struct but present in the section are ignored .