func ParseDefinition(r io.Reader, v interface{}) (err error) {
	// Access the underlying value of the pointer
	def := reflect.ValueOf(v).Elem()

	if !def.IsValid() || !def.CanSet() {
		return ErrWrongVal
	}

	// Deserialized options
	var opts []*unit.UnitOption
	if opts, err = unit.Deserialize(r); err != nil {
		return
	}

	// Loop over deserialized options trying to match them to the ones as found in Definition
	for _, opt := range opts {
		if v := def.FieldByName(opt.Section); v.IsValid() && v.CanSet() {
			if v := v.FieldByName(opt.Name); v.IsValid() && v.CanSet() {
				// reflect.Kind of field in Definition
				switch v.Kind() {

				case reflect.String:
					v.SetString(opt.Value)

				case reflect.Bool:
					if opt.Value == "yes" {
						v.SetBool(true)
					} else if opt.Value != "no" {
						return ParseErr(opt.Name, errors.New(`Value should be "yes" or "no"`))
					}

				case reflect.Slice:
					if _, ok := v.Interface().([]string); ok { // []string
						v.Set(reflect.ValueOf(strings.Fields(opt.Value)))

					} else if _, ok := v.Interface().([]int); ok { // []int
						ints := []int{}
						for _, val := range strings.Fields(opt.Value) {
							if converted, err := strconv.Atoi(val); err == nil {
								ints = append(ints, converted)
							} else {
								return ParseErr(opt.Name, err)
							}
						}
						v.Set(reflect.ValueOf(ints))
					}

				default:
					return ParseErr(opt.Name, ErrUnknownType)
				}
			} else {
				return ParseErr(opt.Name, ErrNotExist)
			}
		} else {
			return ParseErr(opt.Name, ErrNotExist)
		}
	}
	return
}
// ParseDefinition parses the data in Systemd unit-file format and stores the result in value pointed by Definition
ParseDefinition parses the data in Systemd unit-file format and stores the result in value pointed by Definition
// ParseDefinition parses the data in Systemd unit - file format and stores the result in value pointed by Definition
func ParseDefinition(r io.Reader, v interface{}) (err error) {
	def := reflect.ValueOf(v).Elem()
	if !def.IsValid() || !def.CanSet() {
		return ErrWrongVal
	}
	var opts []*unit.UnitOption
	if opts, err = unit.Deserialize(r); err != nil {
		return
	}
	for _, opt := range opts {
		if v := def.FieldByName(opt.Section); v.IsValid() && v.CanSet() {
			if v := v.FieldByName(opt.Name); v.IsValid() && v.CanSet() {
				switch v.Kind() {
				case reflect.String:
					v.SetString(opt.Value)
				case reflect.Bool:
					if opt.Value == "yes" {
						v.SetBool(true)
					} else if opt.Value != "no" {
						return ParseErr(opt.Name, errors.New(`Value should be "yes" or "no"`))
					}
				case reflect.Slice:
					if _, ok := v.Interface().([]string); ok { 
						v.Set(reflect.ValueOf(strings.Fields(opt.Value)))
					} else if _, ok := v.Interface().([]int); ok { 
						ints := []int{}
						for _, val := range strings.Fields(opt.Value) {
							if converted, err := strconv.Atoi(val); err == nil {
								ints = append(ints, converted)
							} else {
								return ParseErr(opt.Name, err)
							}
						}
						v.Set(reflect.ValueOf(ints))
					}
				default:
					return ParseErr(opt.Name, ErrUnknownType)
				}
			} else {
				return ParseErr(opt.Name, ErrNotExist)
			}
		} else {
			return ParseErr(opt.Name, ErrNotExist)
		}
	}
	return
}
func ParseDefinition ( r io . Reader , v interface { } ) ( err error ) { def := reflect . ValueOf ( v ) . Elem ( ) if ! def . IsValid ( ) || ! def . CanSet ( ) { return ErrWrongVal } var opts [ ] * unit . UnitOption if opts , err = unit . Deserialize ( r ) ; err != nil { return } for _ , opt := range opts { if v := def . FieldByName ( opt . Section ) ; v . IsValid ( ) && v . CanSet ( ) { if v := v . FieldByName ( opt . Name ) ; v . IsValid ( ) && v . CanSet ( ) { switch v . Kind ( ) { case reflect . String : v . SetString ( opt . Value ) case reflect . Bool : if opt . Value == " " { v . SetBool ( true ) } else if opt . Value != " " { return ParseErr ( opt . Name , errors . New ( `Value should be "yes" or "no"` ) ) } case reflect . Slice : if _ , ok := v . Interface ( ) . ( [ ] string ) ; ok { v . Set ( reflect . ValueOf ( strings . Fields ( opt . Value ) ) ) } else if _ , ok := v . Interface ( ) . ( [ ] int ) ; ok { ints := [ ] int { } for _ , val := range strings . Fields ( opt . Value ) { if converted , err := strconv . Atoi ( val ) ; err == nil { ints = append ( ints , converted ) } else { return ParseErr ( opt . Name , err ) } } v . Set ( reflect . ValueOf ( ints ) ) } default : return ParseErr ( opt . Name , ErrUnknownType ) } } else { return ParseErr ( opt . Name , ErrNotExist ) } } else { return ParseErr ( opt . Name , ErrNotExist ) } } return }
ParseDefinition parses the data in Systemd unit-file format and stores the result in value pointed by Definition
ParseDefinition parses the data in Systemd unit - file format and stores the result in value pointed by Definition
// Access the underlying value of the pointer // Deserialized options // Loop over deserialized options trying to match them to the ones as found in Definition // reflect.Kind of field in Definition // []string // []int