// Apply deferred functions.
425405
func (p *parseContext) Apply() error {
	for _, apply := range p.apply {
		if err := setField(apply.pos, apply.strct, apply.field, apply.fieldValue); err != nil {
			return err
		}
	}
	p.apply = nil
	return nil
}
1269527
func (c *ConnectionManager) ApplyAll(f ApplyFn) {
	c.Lock()
	defer c.Unlock()
	for k, v := range c.lookup {
		if !f(k, v.transporter) {
			break
		}
	}
}
30559
func (k *KVS) Apply(args *structs.KVSRequest, reply *bool) error {
	if done, err := k.srv.forward("KVS.Apply", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"kvs", "apply"}, time.Now())

	// Perform the pre-apply checks.
	acl, err := k.srv.ResolveToken(args.Token)
	if err != nil {
		return err
	}
	ok, err := kvsPreApply(k.srv, acl, args.Op, &args.DirEnt)
	if err != nil {
		return err
	}
	if !ok {
		*reply = false
		return nil
	}

	// Apply the update.
	resp, err := k.srv.raftApply(structs.KVSRequestType, args)
	if err != nil {
		k.srv.logger.Printf("[ERR] consul.kvs: Apply failed: %v", err)
		return err
	}
	if respErr, ok := resp.(error); ok {
		return respErr
	}

	// Check if the return type is a bool.
	if respBool, ok := resp.(bool); ok {
		*reply = respBool
	}
	return nil
}
856275
func (c *cfn) Apply(s string) (rest string, ok bool) {
	return c.fn(s)
}
1255284
func (c *Client) applyOptions(opts ...ClientOption) error {
	for _, f := range opts {
		if err := f(c); err != nil {
			return err
		}
	}
	return nil
}
601768
func (v *Vector) Apply(m Mutator) {
	var (
		la   Equaler
		min  = v.min.pos
		max  = v.max.pos
		delQ []query
	)

	v.t.Do(func(c llrb.Comparable) (done bool) {
		p := c.(*position)
		if p.pos == max {
			return true
		}
		p.val = m(p.val)
		if p.pos != min && p.pos != max && p.val.Equal(la) {
			delQ = append(delQ, query(p.pos))
		}
		la = p.val
		return
	})

	for _, d := range delQ {
		v.t.Delete(d)
	}
}
613609
func (pipeline *Pipeline) apply(f func(*Node)) {
	head := pipeline.source
	nodes := []*Node{head}
	for len(nodes) > 0 {
		head, nodes = nodes[0], nodes[1:]
		f(head)
		nodes = append(nodes, head.children...)
	}
}
298927
func (a *Authorizer) Apply(next web.HandlerFunc) web.HandlerFunc {
	if a.Checker == nil {
		panic("Authorizer requires an checker function")
	}

	if a.LoginURL == "" {
		a.LoginURL = "/login"
	}
	if a.UnauthorizedMsg == "" {
		a.UnauthorizedMsg = "You are not logged in"
	}
	if a.ForbiddenMsg == "" {
		a.ForbiddenMsg = "You do not have access to this URL"
	}

	return func(ctx web.Context) error {
		auth := ctx.Handler().Authorize()
		if auth == web.AuthAnonymous {
			return next(ctx)
		}

		user := ctx.User()
		if user == nil || user.Anonymous() {
			ct := ctx.ContentType()
			if ct == web.MIMEApplicationJSON {
				//return web.NewError(http.StatusUnauthorized)
				return ctx.Status(http.StatusUnauthorized).JSON(data.Map{
					"url":       ctx.Route(),
					"code":      http.StatusUnauthorized,
					"message":   a.UnauthorizedMsg,
					"login_url": a.LoginURL,
				})
			} else if ctx.IsAJAX() {
				return ctx.Status(http.StatusUnauthorized).HTML(a.UnauthorizedMsg)
			}

			u, err := url.Parse(a.LoginURL)
			if err != nil {
				return err
			}
			q := u.Query()
			q.Set("from", ctx.Request().RequestURI)
			u.RawQuery = q.Encode()
			return ctx.Redirect(u.String())
		}

		if auth == web.AuthExplicit && !a.Checker(user, ctx.Handler()) {
			return web.NewError(http.StatusForbidden, a.ForbiddenMsg)
		}
		return next(ctx)
	}
}
591577
func (e *Event) Apply(em *Element) {
	if em.allowEvents {
		if e.Meta.EventTarget == "" {
			e.Meta.EventTarget = em.EventID()
		}
		e.tree = em
		em.events = append(em.events, e)
	}
}
238666
func (f *Form) Apply(next web.HandlerFunc) web.HandlerFunc {
	if f.CookieName == "" {
		f.CookieName = "_u"
	}
	if f.CookiePath == "" {
		f.CookiePath = "/"
	}
	if f.DefaultURL == "" {
		f.DefaultURL = "/"
	}

	//logger := log.Get(PkgName)
	return func(ctx web.Context) error {
		//logger.Debug("form-auth:", ctx.Request().RequestURI)
		cookie, _ := ctx.Cookie(f.CookieName)
		if cookie != nil {
			user := f.Identifier(cookie.Value)
			ctx.SetUser(user)

			if f.SlidingExpiration && !f.Remember {
				f.renewTicket(ctx, cookie.Value)
			}
		}
		//logger.Debug("user:", ctx.User())

		return next(ctx)
	}
}
558327
func (c *memoryStore) ApplyAll(apply StoreReducer) {
	wg := new(sync.WaitGroup)
	for _, cont := range c.all() {
		wg.Add(1)
		go func(sandbox *Sandbox) {
			apply(sandbox)
			wg.Done()
		}(cont)
	}

	wg.Wait()
}
740768
func (c *CORS) Apply(next web.HandlerFunc) web.HandlerFunc {
	if len(c.AllowOrigins) == 0 {
		c.AllowOrigins = []string{"*"}
	}
	if len(c.AllowMethods) == 0 {
		c.AllowMethods = []string{http.MethodGet, http.MethodPost, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodDelete}
	}

	allowMethods := strings.Join(c.AllowMethods, ",")
	allowHeaders := strings.Join(c.AllowHeaders, ",")
	exposeHeaders := strings.Join(c.ExposeHeaders, ",")
	maxAge := strconv.Itoa(c.MaxAge)

	return func(ctx web.Context) error {
		r := ctx.Request()
		w := ctx.Response()
		origin := r.Header.Get(web.HeaderOrigin)
		if origin == "" {
			return next(ctx)
		}

		// Check allowed origins
		var allowOrigin string
		for _, o := range c.AllowOrigins {
			if o == "*" || o == origin {
				allowOrigin = o
				break
			}
		}

		// Simple request
		if r.Method != http.MethodOptions {
			w.Header().Add(web.HeaderVary, web.HeaderOrigin)
			w.Header().Set(web.HeaderAccessControlAllowOrigin, allowOrigin)
			if c.AllowCredentials {
				w.Header().Set(web.HeaderAccessControlAllowCredentials, "true")
			}
			if exposeHeaders != "" {
				w.Header().Set(web.HeaderAccessControlExposeHeaders, exposeHeaders)
			}
			return next(ctx)
		}

		// Preflight request
		w.Header().Add(web.HeaderVary, web.HeaderOrigin)
		w.Header().Add(web.HeaderVary, web.HeaderAccessControlRequestMethod)
		w.Header().Add(web.HeaderVary, web.HeaderAccessControlRequestHeaders)
		w.Header().Set(web.HeaderAccessControlAllowOrigin, allowOrigin)
		w.Header().Set(web.HeaderAccessControlAllowMethods, allowMethods)
		if c.AllowCredentials {
			w.Header().Set(web.HeaderAccessControlAllowCredentials, "true")
		}
		if allowHeaders != "" {
			w.Header().Set(web.HeaderAccessControlAllowHeaders, allowHeaders)
		} else {
			h := r.Header.Get(web.HeaderAccessControlRequestHeaders)
			if h != "" {
				w.Header().Set(web.HeaderAccessControlAllowHeaders, h)
			}
		}
		if c.MaxAge > 0 {
			w.Header().Set(web.HeaderAccessControlMaxAge, maxAge)
		}
		return ctx.Status(http.StatusNoContent).Empty()
	}
}
674526
func (p *Proxy) Apply(dbName string, i interface{}) {
	p.ApplyLazy(gsd.Lazy(dbName), i)
}
1244166
func (state *WorldState) Apply(diff WorldStateDiff) {

nextRemoved:
	for _, removed := range diff.Removed {
		for i, e := range state.Entities {
			if e.EntityId() == removed.EntityId() {
				state.Entities = append(state.Entities[:i], state.Entities[i+1:]...)
				continue nextRemoved
			}
		}
	}

nextAddedOrModified:
	for _, added := range diff.Entities {
		for i, e := range state.Entities {
			if added.EntityId() == e.EntityId() {
				state.Entities[i] = added
				continue nextAddedOrModified
			}
		}

		state.Entities = append(state.Entities, added)
	}

	switch len(diff.TerrainMapSlices) {
	default:
		state.TerrainMap.MergeDiff(diff.Bounds, diff.TerrainMapSlices...)
	case 1:
		if state.Bounds.Overlaps(diff.Bounds) {
			state.TerrainMap.MergeDiff(diff.Bounds, diff.TerrainMapSlices...)
		} else {
			slice := diff.TerrainMapSlices[0]
			tm, err := NewTerrainMap(slice.Bounds, slice.Terrain)
			if err != nil {
				panic(fmt.Sprintf("error applying diff: %v", err))
			}
			state.TerrainMap.TerrainMap = tm
		}
	case 0:
	}

	state.Time = diff.Time
	state.Bounds = diff.Bounds
}
842313
func DeferredPublish(topic string, delay time.Duration, body []byte) *Command {
	var params = [][]byte{[]byte(topic), []byte(strconv.Itoa(int(delay / time.Millisecond)))}
	return &Command{[]byte("DPUB"), params, body}
}
473591
func (cm *Validator) Apply(configEnv *cb.ConfigEnvelope) error {
	cm.AppliedConfigUpdateEnvelope = configEnv
	return cm.ApplyVal
}
707968
func (w *Waiter) ApplyOptions(opts ...WaiterOption) {
	for _, fn := range opts {
		fn(w)
	}
}