func header(r *http.Request, key string) (string, bool) { if r.Header == nil { return "", false } if candidate := r.Header[key]; !misc.ZeroOrNil(candidate) { return candidate[0], true } return "", false }
func (config *Config) complete() bool { cfgs := reflect.ValueOf(config).Elem() for i := 0; i < cfgs.NumField(); i++ { if misc.ZeroOrNil(cfgs.Field(i).Interface()) { return false } } return true }
func (config *Config) merge(arg Config) *Config { mine := reflect.ValueOf(config).Elem() theirs := reflect.ValueOf(&arg).Elem() for i := 0; i < mine.NumField(); i++ { myField := mine.Field(i) if misc.ZeroOrNil(myField.Interface()) { myField.Set(reflect.ValueOf(theirs.Field(i).Interface())) } } return config }
func toStringArray(values string) []string { if misc.ZeroOrNil(values) { return []string{} } return strings.Split(values, ",") }