/*
   Set header "field" to "value".
*/
184286
func (this *Response) Set(f string, v string) {
	if v == "" {
		this.RemoveHeader(f)
	} else {
		this.SetHeader(f, v)
	}
}
1359894
func SetFlorenceHeader(ctx context.Context, r *http.Request) {
	if IsFlorenceIdentityPresent(ctx) {
		r.Header.Set(FlorenceHeaderKey, ctx.Value(FlorenceIdentityKey).(string))
	}
}
604742
func (r *Response) Set(key, value string) {
	r.handlerHeader.Set(key, value)
}
738768
func (f *FieldConfig) Set(data string) error {
	return convert(data, f.Value)
}
1125124
func (dt *DbfTable) SetFieldValue(row int, fieldIndex int, value string) {
	dt.frozenStruct = true // table structure can not be changed from this point

	b := []byte(value)
	fieldLength := int(dt.fields[fieldIndex].Length)

	// locate the offset of the field in DbfTable dataStore
	offset := dt.getRowOffset(row)
	recordOffset := 1

	//fmt.Println("total fields: ", dt.fields)
	for i := 0; i < len(dt.fields); i++ {
		if i == fieldIndex {
			break
		} else {
			recordOffset += int(dt.fields[i].Length)
		}
	}

	// first fill the field with space values
	for i := 0; i < fieldLength; i++ {
		dt.dataStore[offset+recordOffset+i] = 0x20
	}

	// write new value
	// TODO: this should use copy() or other fast way to move data
	switch dt.fields[fieldIndex].Type {
	case "C", "L", "D":
		for i := 0; i < len(b) && i < fieldLength; i++ {
			dt.dataStore[offset+recordOffset+i] = b[i]
		}
	case "N":
		for i := 0; i < fieldLength; i++ {
			if i < len(b) {
				dt.dataStore[offset+recordOffset+(fieldLength-i-1)] = b[(len(b)-1)-i]
			} else {
				break
			}
		}
	}
}
770250
func (r *Response) SetHeader(key, value string) *Response {
	r.Header.Set(key, value)
	return r
}
501233
func (s *PipelineDescription) SetFields(v []*Field) *PipelineDescription {
	s.Fields = v
	return s
}
196184
func (o *rawSet) setFieldValue(ind reflect.Value, value interface{}) {
	switch ind.Kind() {
	case reflect.Bool:
		if value == nil {
			ind.SetBool(false)
		} else if v, ok := value.(bool); ok {
			ind.SetBool(v)
		} else {
			v, _ := StrTo(ToStr(value)).Bool()
			ind.SetBool(v)
		}

	case reflect.String:
		if value == nil {
			ind.SetString("")
		} else {
			ind.SetString(ToStr(value))
		}

	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		if value == nil {
			ind.SetInt(0)
		} else {
			val := reflect.ValueOf(value)
			switch val.Kind() {
			case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
				ind.SetInt(val.Int())
			case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				ind.SetInt(int64(val.Uint()))
			default:
				v, _ := StrTo(ToStr(value)).Int64()
				ind.SetInt(v)
			}
		}
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		if value == nil {
			ind.SetUint(0)
		} else {
			val := reflect.ValueOf(value)
			switch val.Kind() {
			case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
				ind.SetUint(uint64(val.Int()))
			case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
				ind.SetUint(val.Uint())
			default:
				v, _ := StrTo(ToStr(value)).Uint64()
				ind.SetUint(v)
			}
		}
	case reflect.Float64, reflect.Float32:
		if value == nil {
			ind.SetFloat(0)
		} else {
			val := reflect.ValueOf(value)
			switch val.Kind() {
			case reflect.Float64:
				ind.SetFloat(val.Float())
			default:
				v, _ := StrTo(ToStr(value)).Float64()
				ind.SetFloat(v)
			}
		}

	case reflect.Struct:
		if value == nil {
			ind.Set(reflect.Zero(ind.Type()))

		} else if _, ok := ind.Interface().(time.Time); ok {
			var str string
			switch d := value.(type) {
			case time.Time:
				o.orm.alias.DbBaser.TimeFromDB(&d, o.orm.alias.TZ)
				ind.Set(reflect.ValueOf(d))
			case []byte:
				str = string(d)
			case string:
				str = d
			}
			if str != "" {
				if len(str) >= 19 {
					str = str[:19]
					t, err := time.ParseInLocation(formatDateTime, str, o.orm.alias.TZ)
					if err == nil {
						t = t.In(DefaultTimeLoc)
						ind.Set(reflect.ValueOf(t))
					}
				} else if len(str) >= 10 {
					str = str[:10]
					t, err := time.ParseInLocation(formatDate, str, DefaultTimeLoc)
					if err == nil {
						ind.Set(reflect.ValueOf(t))
					}
				}
			}
		}
	}
}
342837
func setFields(fieldValue reflect.Value, val parse.Parser) error {
	if fieldValue.CanSet() {
		fieldValue.Set(reflect.ValueOf(val).Elem().Convert(fieldValue.Type()))
	} else {
		return fmt.Errorf("%s is not settable", fieldValue.Type().String())
	}
	return nil
}
800152
func (msg *Message) SetDateHeader(field string, date time.Time) {
	msg.header[field] = []string{msg.FormatDate(date)}
}
527165
func (dt *DbfTable) SetFieldValueByName(row int, fieldName string, value string) {
	fieldName = strings.ToUpper(fieldName)
	fieldIndex, ok := dt.fieldMap[fieldName]
	if !ok {
		panic("Field name '" + fieldName + "' does not exist")
	}
	// set field value and return
	dt.SetFieldValue(row, fieldIndex, value)
}
21579
func Header(name, val string) RequestOption {
	return func(req *http.Request) error {
		req.Header.Add(name, val)
		return nil
	}
}
178721
func (dt *DbfTable) SetFieldValueByName(row int, fieldName string, value string) (err error) {
	if fieldIndex, found := dt.fieldMap[fieldName]; found {
		return dt.SetFieldValue(row, fieldIndex, value)
	}
	return errors.New("Field name \"" + fieldName + "\" does not exist")
}
1037980
func (c *keyStringValueChanger) SetValue(value string) (string, error) {
	if c.err != nil {
		return "", c.err
	}
	current := c.node.content.value().(string)
	c.node.content = keyValue{c.node.content.key(), value}
	return current, nil
}
1013833
func (self *simplePBundle) Header(s string) (string, bool) {
	v, ok := self.h[strings.ToLower(s)]
	return v, ok
}
960714
func SetField(src interface{}, v reflect.Value, fieldName string) error {
	field := v.FieldByName(fieldName)
	if !field.IsValid() {
		return fmt.Errorf("couldn't find %v field in %T", fieldName, v.Interface())
	}
	srcValue := reflect.ValueOf(src)
	if srcValue.Type().AssignableTo(field.Type()) {
		field.Set(srcValue)
		return nil
	}
	if srcValue.Type().ConvertibleTo(field.Type()) {
		field.Set(srcValue.Convert(field.Type()))
		return nil
	}
	return fmt.Errorf("couldn't assign/convert %v to %v", srcValue.Type(), field.Type())
}
661528
func (k *Client) SetHeader(param string, value string) {
	k.Header[param] = value
}