// getUserAgentFromContext returns the previously saved user-agent context stored in ctx, if one exists
497817
func getUserAgentFromContext(ctx context.Context) string {
	var upstreamUA string
	if ctx != nil {
		var ki interface{} = ctx.Value(UAStringKey{})
		if ki != nil {
			upstreamUA = ctx.Value(UAStringKey{}).(string)
		}
	}
	return upstreamUA
}
206568
func (s *StatusEvent) GetContext() string {
	if s == nil || s.Context == nil {
		return ""
	}
	return *s.Context
}
1126930
func (tx *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
	return GetContext(ctx, tx, dest, query, args...)
}
1262753
func WithUserAgent(agent string) ConfigFunc {
	return func(c *Client) {
		ot := c.client.Transport
		c.client.Transport = rtFunc(func(r *http.Request) (*http.Response, error) {
			nagent := agent
			if agent != "" {
				nagent = fmt.Sprintf(" (%s)", nagent)
			}

			r.Header.Set("User-Agent", fmt.Sprintf("go-manifold-%s%s", manifold.Version, nagent))
			return ot.RoundTrip(r)
		})
	}
}
1196463
func (api *Client) GetUserPresenceContext(ctx context.Context, user string) (*UserPresence, error) {
	values := url.Values{
		"token": {api.token},
		"user":  {user},
	}

	response, err := api.userRequest(ctx, "users.getPresence", values)
	if err != nil {
		return nil, err
	}
	return &response.UserPresence, nil
}
502721
func GetContext(sp *Spider, req *request.Request) *Context {
	ctx := contextPool.Get().(*Context)
	ctx.spider = sp
	ctx.Request = req
	return ctx
}
464533
func UserAgentHandler(name string) func(next xhandler.HandlerC) xhandler.HandlerC {
	return func(next xhandler.HandlerC) xhandler.HandlerC {
		return xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
			if ua := r.Header.Get("User-Agent"); ua != "" {
				FromContext(ctx).SetField(name, ua)
			}
			next.ServeHTTPC(ctx, w, r)
		})
	}
}
715004
func getContext(marker interface{}) *context {
	globals.lockContexts.Lock()
	defer globals.lockContexts.Unlock()
	if globals.contexts == nil {
		return nil
	}
	c, ok := globals.contexts[marker]
	if !ok {
		return &consts.defaultContext
	}
	return c
}
1175884
func NewContext(
	agentConfig agent.ConfigSetter,
	api api.Connection,
	st StateBackend,
) Context {
	return &upgradeContext{
		agentConfig: agentConfig,
		api:         api,
		st:          st,
	}
}
1000236
func (client *BaseClient) GetClientContext(
	settings *InvokeSettings) (context *ClientContext) {
	context = client.contextPool.Get().(*ClientContext)
	context.InitBaseContext()
	context.Client = client
	context.Retried = 0
	if client.UserData != nil {
		for k, v := range client.UserData {
			context.SetInterface(k, v)
		}
	}
	if settings == nil {
		context.InvokeSettings = InvokeSettings{
			Timeout: client.timeout,
			Retry:   client.retry,
		}
	} else {
		if settings.userData != nil {
			for k, v := range settings.userData {
				context.SetInterface(k, v)
			}
		}
		context.InvokeSettings = *settings
		if settings.Timeout <= 0 {
			context.Timeout = client.timeout
		}
		if settings.Retry <= 0 {
			context.Retry = client.retry
		}
	}
	return context
}
1329062
func FromContext(ctx context.Context) (*Identity, bool) {
	// ctx.Value returns nil if ctx has no value for the key;
	p, ok := ctx.Value(idtKey).(*Identity)
	return p, ok
}
742927
func (api *Client) GetUserInfo(user string) (*User, error) {
	return api.GetUserInfoContext(context.Background(), user)
}
571688
func NewPersonContext(ctx context.Context, p *Person) context.Context {
	return context.WithValue(ctx, personKey, p)
}
210560
func (c *Component) GetContext(token string) context.Context {
	if c.Context == nil {
		c.initBgCtx()
	}
	ctx := c.Context
	if token == "" && c.Identity != nil {
		token, _ = c.BuildJWT()
	}
	ctx = ttnctx.OutgoingContextWithToken(ctx, token)
	return ctx
}
894193
func FromContext(ctx context.Context) (Logger, bool) {
	l, ok := ctx.Value(loggerKey).(Logger)
	return l, ok
}
441749
func WithUserAgent(s string) DialOption {
	return newFuncDialOption(func(o *dialOptions) {
		o.copts.UserAgent = s
	})
}
630057
func GetContext(err error, key string) interface{} {
	if e, ok := err.(withContext); ok {
		return e.Get(key)
	}
	return ""
}