// BindStructWithConfig martini handler for bind struct
199848
func BindStructWithConfig(obj interface{}, config Config) gin.HandlerFunc {
	return func(c *gin.Context) {
		inj, exist := apiutil.Get(c)
		if !exist {
			c.AbortWithError(http.StatusServiceUnavailable, ErrorInjectorNotFound.New(nil))
			return
		}

		bindStruct := reflect.New(reflect.TypeOf(obj))
		defer func() {
			inj.Map(bindStruct.Elem().Interface())
		}()

		req := c.Request

		if !config.DisableBindQuery {
			if err := bindQuery(bindStruct, req); err != nil {
				c.Error(err)
				return
			}
		}

		if !config.DisableBindParams {
			if err := bindParams(bindStruct, c.Params); err != nil {
				c.Error(err)
				return
			}
		}

		if err := c.Bind(bindStruct.Interface()); err != nil {
			c.Error(err)
			return
		}

		// contentType := req.Header.Get("Content-Type")
		// if contentType != "" {
		// 	if strings.Contains(contentType, "json") {
		// 		if err = bindJSONBody(bindStruct, req); err != nil {
		// 			return
		// 		}
		// 	} else if strings.Contains(contentType, "multipart/form-data") {
		// 		if err = bindMultipartForm(bindStruct, config, req); err != nil {
		// 			return
		// 		}
		// 	}
		// }
		//
		if !config.DisableTrimSpace {
			if err := trimstructspace.TrimStructSpace(bindStruct.Interface()); err != nil {
				c.Error(err)
				return
			}
		}

		if !config.DisableGoValidator {
			ok, err := govalidator.ValidateStruct(bindStruct.Interface())
			if err != nil {
				c.Error(err)
				return
			}
			if !ok {
				c.Error(errutil.New("invalid parameters"))
				return
			}
		}

		return
	}
}
1209469
func (o *untypedRequestBinder) Bind(request *http.Request, routeParams RouteParams, consumer runtime.Consumer, data interface{}) error {
	val := reflect.Indirect(reflect.ValueOf(data))
	isMap := val.Kind() == reflect.Map
	var result []error
	debugLog("binding %d parameters for %s %s", len(o.Parameters), request.Method, request.URL.EscapedPath())
	for fieldName, param := range o.Parameters {
		binder := o.paramBinders[fieldName]
		debugLog("binding parameter %s for %s %s", fieldName, request.Method, request.URL.EscapedPath())
		var target reflect.Value
		if !isMap {
			binder.Name = fieldName
			target = val.FieldByName(fieldName)
		}

		if isMap {
			tpe := binder.Type()
			if tpe == nil {
				if param.Schema.Type.Contains("array") {
					tpe = reflect.TypeOf([]interface{}{})
				} else {
					tpe = reflect.TypeOf(map[string]interface{}{})
				}
			}
			target = reflect.Indirect(reflect.New(tpe))

		}

		if !target.IsValid() {
			result = append(result, errors.New(500, "parameter name %q is an unknown field", binder.Name))
			continue
		}

		if err := binder.Bind(request, routeParams, consumer, target); err != nil {
			result = append(result, err)
			continue
		}

		if binder.validator != nil {
			rr := binder.validator.Validate(target.Interface())
			if rr != nil && rr.HasErrors() {
				result = append(result, rr.AsError())
			}
		}

		if isMap {
			val.SetMapIndex(reflect.ValueOf(param.Name), target)
		}
	}

	if len(result) > 0 {
		return errors.CompositeValidationError(result...)
	}

	return nil
}
703324
func NewStructTypeDef(init ...*StructTypeDef) *StructTypeDef {
	var o *StructTypeDef
	if len(init) == 1 {
		o = init[0]
	} else {
		o = new(StructTypeDef)
	}
	return o.Init()
}
921338
func (p *Pool) AddStruct(ctx context.Context, s interface{}) {
	id, err := p.lock.Lock()
	if err == nil {
		defer p.lock.Unlock(id)

		addr := fmt.Sprintf("%p", s)
		log.LoggerWContext(ctx).Debug("Adding struct with address " + addr + " to the pool")

		p.structs[addr] = s
		p.refreshStruct(ctx, s)
	}
}
1127925
func (b *ETCDBindingStorage) PutBinding(uid string) error {
	_, err := b.cli.Put(context.Background(), getUserBindingKey(uid, b.thisServer.Type), b.thisServer.ID, clientv3.WithLease(b.leaseID))
	return err
}
206609
func (c *Tethering) BindWithParams(v *TetheringBindParams) (*gcdmessage.ChromeResponse, error) {
	return gcdmessage.SendDefaultRequest(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Tethering.bind", Params: v})
}
1136602
func (c *Client) DeclareBinding(vhost string, info BindingInfo) (res *http.Response, err error) {
	info.Vhost = vhost

	if info.Arguments == nil {
		info.Arguments = make(map[string]interface{})
	}
	body, err := json.Marshal(info)
	if err != nil {
		return nil, err
	}

	req, err := newRequestWithBody(c, "POST", "bindings/"+PathEscape(vhost)+
		"/e/"+PathEscape(info.Source)+"/"+PathEscape(string(info.DestinationType[0]))+
		"/"+PathEscape(info.Destination), body)

	if err != nil {
		return nil, err
	}

	res, err = executeRequest(c, req)
	if err != nil {
		return nil, err
	}

	return res, nil
}
1190698
func (r *resolver) bind(id *syntax.Ident, allowRebind bool) bool {
	// Binding outside any local (comprehension/function) block?
	if r.env.isModule() {
		id.Scope = uint8(Global)
		prev, ok := r.globals[id.Name]
		if ok {
			// Global reassignments are permitted only if
			// they are of the form x += y.  We can't tell
			// statically whether it's a reassignment
			// (e.g. int += int) or a mutation (list += list).
			if !allowRebind && !AllowGlobalReassign {
				r.errorf(id.NamePos, "cannot reassign global %s declared at %s", id.Name, prev.NamePos)
			}
			id.Index = prev.Index
		} else {
			// first global binding of this name
			r.globals[id.Name] = id
			id.Index = len(r.moduleGlobals)
			r.moduleGlobals = append(r.moduleGlobals, id)
		}
		return ok
	}

	// Mark this name as local to current block.
	// Assign it a new local (positive) index in the current container.
	_, ok := r.env.bindings[id.Name]
	if !ok {
		var locals *[]*syntax.Ident
		if fn := r.container().function; fn != nil {
			locals = &fn.Locals
		} else {
			locals = &r.moduleLocals
		}
		r.env.bind(id.Name, binding{Local, len(*locals)})
		*locals = append(*locals, id)
	}

	r.use(id)
	return ok
}
561624
func SecureWithConfig(config SecureConfig) echo.MiddlewareFunc {
	// Defaults
	if config.Skipper == nil {
		config.Skipper = DefaultSecureConfig.Skipper
	}

	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			if config.Skipper(c) {
				return next(c)
			}

			req := c.Request()
			res := c.Response()

			if config.XSSProtection != "" {
				res.Header().Set(echo.HeaderXXSSProtection, config.XSSProtection)
			}
			if config.ContentTypeNosniff != "" {
				res.Header().Set(echo.HeaderXContentTypeOptions, config.ContentTypeNosniff)
			}
			if config.XFrameOptions != "" {
				res.Header().Set(echo.HeaderXFrameOptions, config.XFrameOptions)
			}
			if (c.IsTLS() || (req.Header.Get(echo.HeaderXForwardedProto) == "https")) && config.HSTSMaxAge != 0 {
				subdomains := ""
				if !config.HSTSExcludeSubdomains {
					subdomains = "; includeSubdomains"
				}
				if config.HSTSPreloadEnabled {
					subdomains = fmt.Sprintf("%s; preload", subdomains)
				}
				res.Header().Set(echo.HeaderStrictTransportSecurity, fmt.Sprintf("max-age=%d%s", config.HSTSMaxAge, subdomains))
			}
			if config.ContentSecurityPolicy != "" {
				if config.CSPReportOnly {
					res.Header().Set(echo.HeaderContentSecurityPolicyReportOnly, config.ContentSecurityPolicy)
				} else {
					res.Header().Set(echo.HeaderContentSecurityPolicy, config.ContentSecurityPolicy)
				}
			}
			return next(c)
		}
	}
}
28847
func (c *Context) MustBindWith(obj interface{}, b binding.Binding) error {
	if err := c.ShouldBindWith(obj, b); err != nil {
		c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) // nolint: errcheck
		return err
	}
	return nil
}
449915
func (sr *Stackers) Bind(r Reactor, cl bool) {
	var lr Connector
	var err error

	if lr, err = sr.Last(); err != nil {
		sr.Reactor.Bind(r, cl)
		sr.ro.Lock()
		{
			sr.stacks = append(sr.stacks, r)
		}
		sr.ro.Unlock()
		return
	}

	lr.Bind(r, cl)
	sr.ro.Lock()
	{
		sr.stacks = append(sr.stacks, r)
	}
	sr.ro.Unlock()
}
877111
func getDataStruct(xr *XorRand) *dataStruct {
	var ds *dataStruct
	switch binDataType {
	case "B":
		ds = &dataStruct{B: randBytes(binDataSize, xr)}
	case "S":
		ds = &dataStruct{S: string(randBytes(binDataSize, xr))}
	default:
		ds = &dataStruct{I: xr.Int64()}
	}

	return ds
}
998394
func (p *Imports) Bind(opts libs.SassOptions) {
	entries := make([]libs.ImportEntry, p.Len())
	i := 0

	p.RLock()
	for _, ent := range p.m {
		bs := ent.bytes
		entries[i] = libs.ImportEntry{
			Parent: ent.Prev,
			Path:   ent.Path,
			Source: string(bs),
		}
		i++
	}
	p.RUnlock()

	resolver := func(url string, prev string) (newURL string, body string, resolved bool) {
		if p.resolver != nil {
			newURL, body, resolved = p.resolver(url, prev)
			if resolved {
				return
			}
		}
		entry, err := libs.GetEntry(entries, prev, url)
		if err == nil {
			return url, entry, true
		}
		return "", "", false
	}

	// set entries somewhere so GC doesn't collect it
	p.idx = libs.BindImporter(opts, resolver)
}
923675
func (cMgr *ConfigurationManager) handleStruct(rValue reflect.Value, tagName string) error {
	structType := rValue.Type()
	numOfField := structType.NumField()

	for i := 0; i < numOfField; i++ {
		structField := structType.Field(i)
		fieldValue := rValue.Field(i)
		keyName := cMgr.getKeyName(structField.Name, structField.Tag)
		if keyName == ignoreField {
			return nil
		}

		switch structField.Type.Kind() {
		case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
			reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16,
			reflect.Uint32, reflect.Uint64, reflect.Bool, reflect.Interface, reflect.Array,
			reflect.Slice:
			if fieldValue.CanSet() {
				err := cMgr.setValue(fieldValue, getTagKey(tagName, keyName))
				if err != nil {
					return err
				}
			}
		case reflect.Ptr:
			err := cMgr.handlePtr(fieldValue, getTagKey(tagName, keyName))
			if err != nil {
				return err
			}
		case reflect.Struct:
			err := cMgr.handleStruct(fieldValue, getTagKey(tagName, keyName))
			if err != nil {
				return err
			}
		case reflect.Map:
			err := cMgr.handleMap(rValue, fieldValue, getTagKey(tagName, keyName))
			if err != nil {
				return err
			}
		case reflect.Uintptr, reflect.Complex64, reflect.Complex128, reflect.Chan, reflect.Func,
			reflect.UnsafePointer:
			// ignore
		}
	}

	return nil
}
108957
func SecureWithConfig(config SecureConfig) echo.MiddlewareFuncd {
	// Defaults
	if config.Skipper == nil {
		config.Skipper = DefaultSecureConfig.Skipper
	}

	return func(next echo.Handler) echo.HandlerFunc {
		return func(c echo.Context) error {
			if config.Skipper(c) {
				return next.Handle(c)
			}

			req := c.Request()
			hdr := c.Response().Header()

			if config.XSSProtection != "" {
				hdr.Set(echo.HeaderXXSSProtection, config.XSSProtection)
			}
			if config.ContentTypeNosniff != "" {
				hdr.Set(echo.HeaderXContentTypeOptions, config.ContentTypeNosniff)
			}
			if config.XFrameOptions != "" {
				hdr.Set(echo.HeaderXFrameOptions, config.XFrameOptions)
			}
			if (req.IsTLS() || (req.Header().Get(echo.HeaderXForwardedProto) == "https")) && config.HSTSMaxAge != 0 {
				subdomains := ""
				if !config.HSTSExcludeSubdomains {
					subdomains = "; includeSubdomains"
				}
				hdr.Set(echo.HeaderStrictTransportSecurity, fmt.Sprintf("max-age=%d%s", config.HSTSMaxAge, subdomains))
			}
			if config.ContentSecurityPolicy != "" {
				hdr.Set(echo.HeaderContentSecurityPolicy, config.ContentSecurityPolicy)
			}
			return next.Handle(c)
		}
	}
}
1182308
func WithConfig(cfg Config) *Hist {
	var h Hist
	h.Init(cfg)
	return &h
}
256328
func BindFields(obj interface{}) Fields {
	t := reflect.TypeOf(obj)
	v := reflect.ValueOf(obj)
	fields := make(map[string]*Field)

	if t.Kind() == reflect.Ptr {
		t = t.Elem()
		v = v.Elem()
	}

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

		tag := extractTag(field.Tag)
		if tag == "-" {
			continue
		}

		fieldType := field.Type

		if fieldType.Kind() == reflect.Ptr {
			fieldType = fieldType.Elem()
		}

		var graphType Output
		if fieldType.Kind() == reflect.Struct {
			structFields := BindFields(v.Field(i).Interface())

			if tag == "" {
				fields = appendFields(fields, structFields)
				continue
			} else {
				graphType = NewObject(ObjectConfig{
					Name:   tag,
					Fields: structFields,
				})
			}
		}

		if tag == "" {
			continue
		}

		if graphType == nil {
			graphType = getGraphType(fieldType)
		}
		fields[tag] = &Field{
			Type: graphType,
			Resolve: func(p ResolveParams) (interface{}, error) {
				return extractValue(tag, p.Source), nil
			},
		}
	}
	return fields
}