예제 #1
0
func InboundDestinationFromContext(ctx context.Context) net.Destination {
	v := ctx.Value(inboundDestinationKey)
	if v == nil {
		return net.Destination{}
	}
	return v.(net.Destination)
}
예제 #2
0
파일: auth.go 프로젝트: iserko/empire
// UserFromContext returns a user from a context.Context if one is present.
func UserFromContext(ctx context.Context) *empire.User {
	u, ok := ctx.Value(userKey).(*empire.User)
	if !ok {
		panic("expected user to be authenticated")
	}
	return u
}
예제 #3
0
파일: context.go 프로젝트: kego/ke
func FromContextOrNil(ctx context.Context) *App {
	e, ok := ctx.Value(ctxKey).(*App)
	if ok {
		return e
	}
	return nil
}
예제 #4
0
파일: cmdctx.go 프로젝트: kego/ke
// FromContext returns the User value stored in ctx, if any.
func FromContext(ctx context.Context) *Cmd {
	e, ok := ctx.Value(cmdKey).(*Cmd)
	if !ok {
		panic(kerr.New("OQVLBQFQJW", "No cmd in ctx").Error())
	}
	return e
}
예제 #5
0
파일: dial.go 프로젝트: Harvey-OS/go
// dialSingle attempts to establish and returns a single connection to
// the destination address.
func dialSingle(ctx context.Context, dp *dialParam, ra Addr) (c Conn, err error) {
	trace, _ := ctx.Value(nettrace.TraceKey{}).(*nettrace.Trace)
	if trace != nil {
		raStr := ra.String()
		if trace.ConnectStart != nil {
			trace.ConnectStart(dp.network, raStr)
		}
		if trace.ConnectDone != nil {
			defer func() { trace.ConnectDone(dp.network, raStr, err) }()
		}
	}
	la := dp.LocalAddr
	switch ra := ra.(type) {
	case *TCPAddr:
		la, _ := la.(*TCPAddr)
		c, err = dialTCP(ctx, dp.network, la, ra)
	case *UDPAddr:
		la, _ := la.(*UDPAddr)
		c, err = dialUDP(ctx, dp.network, la, ra)
	case *IPAddr:
		la, _ := la.(*IPAddr)
		c, err = dialIP(ctx, dp.network, la, ra)
	case *UnixAddr:
		la, _ := la.(*UnixAddr)
		c, err = dialUnix(ctx, dp.network, la, ra)
	default:
		return nil, &OpError{Op: "dial", Net: dp.network, Source: la, Addr: ra, Err: &AddrError{Err: "unexpected address type", Addr: dp.address}}
	}
	if err != nil {
		return nil, &OpError{Op: "dial", Net: dp.network, Source: la, Addr: ra, Err: err} // c is non-nil interface containing nil pointer
	}
	return c, nil
}
예제 #6
0
파일: poster.go 프로젝트: docker/containerd
func GetPoster(ctx context.Context) Poster {
	poster := ctx.Value(posterKey{})
	if poster == nil {
		logger := log.G(ctx)
		tx, _ := getTx(ctx)
		topic := getTopic(ctx)

		// likely means we don't have a configured event system. Just return
		// the default poster, which merely logs events.
		return posterFunc(func(ctx context.Context, event Event) {
			fields := logrus.Fields{"event": event}

			if topic != "" {
				fields["topic"] = topic
			}

			if tx != nil {
				fields["tx.id"] = tx.id
				if tx.parent != nil {
					fields["tx.parent.id"] = tx.parent.id
				}
			}

			logger.WithFields(fields).Info("event posted")
		})
	}

	return poster.(Poster)
}
예제 #7
0
파일: auth.go 프로젝트: z0rr0/luss
// ExtractUser extracts user from from context.
func ExtractUser(ctx context.Context) (*User, error) {
	u, ok := ctx.Value(userKey).(*User)
	if !ok {
		return nil, errors.New("not found context user")
	}
	return u, nil
}
예제 #8
0
파일: wgctx.go 프로젝트: kego/ke
func FromContextOrNil(ctx context.Context) *sync.WaitGroup {
	wg, ok := ctx.Value(wgKey).(*sync.WaitGroup)
	if !ok {
		return nil
	}
	return wg
}
예제 #9
0
파일: jsonctx.go 프로젝트: kego/ke
// FromContext returns the Cache value stored in ctx, and panics if it's not found.
func FromContext(ctx context.Context) *JsonCache {
	e, ok := ctx.Value(jsonKey).(*JsonCache)
	if !ok {
		panic(kerr.New("XUTUUVDMMX", "No json cache in ctx").Error())
	}
	return e
}
예제 #10
0
파일: middleware.go 프로젝트: goji/goji
/*
Handler returns the handler corresponding to the most recently matched Pattern,
or nil if no pattern was matched.

The handler returned by this function is the one that will be dispatched to at
the end of the middleware stack. If the returned Handler is nil, http.NotFound
will be used instead.
*/
func Handler(ctx context.Context) http.Handler {
	h := ctx.Value(internal.Handler)
	if h == nil {
		return nil
	}
	return h.(http.Handler)
}
예제 #11
0
파일: wgctx.go 프로젝트: kego/ke
// FromContext returns the User value stored in ctx, if any.
func FromContext(ctx context.Context) *sync.WaitGroup {
	wg, ok := ctx.Value(wgKey).(*sync.WaitGroup)
	if !ok {
		panic(kerr.New("UNYGADKEGY", "No wg in ctx").Error())
	}
	return wg
}
예제 #12
0
파일: middleware.go 프로젝트: goji/goji
/*
Pattern returns the most recently matched Pattern, or nil if no pattern was
matched.
*/
func Pattern(ctx context.Context) goji.Pattern {
	p := ctx.Value(internal.Pattern)
	if p == nil {
		return nil
	}
	return p.(goji.Pattern)
}
예제 #13
0
// ResponseTypeFromCtx gives the content type that was parsed from the
// 'Accept' header.
func ResponseTypeFromCtx(ctx context.Context) *ContentType {
	ct := ctx.Value(httpware.ResponseContentTypeKey)
	if ct == nil {
		return nil
	}
	return ct.(*ContentType)
}
예제 #14
0
func OutboundTagFromContext(ctx context.Context) string {
	v := ctx.Value(outboundTagKey)
	if v == nil {
		return ""
	}
	return v.(string)
}
예제 #15
0
파일: helpers.go 프로젝트: goposse/goro
// ParamsFromContext - get the current params value from a given context
func ParamsFromContext(ctx context.Context) url.Values {
	params := ctx.Value("params")
	if params != nil {
		return url.Values(params.(map[string][]string))
	}
	return nil
}
예제 #16
0
파일: jsonctx.go 프로젝트: kego/ke
func FromContextOrNil(ctx context.Context) *JsonCache {
	e, ok := ctx.Value(jsonKey).(*JsonCache)
	if ok {
		return e
	}
	return nil
}
예제 #17
0
func UserFromContext(ctx context.Context) *User {
	v := ctx.Value(userKey)
	if v == nil {
		return nil
	}
	return v.(*User)
}
예제 #18
0
파일: envctx.go 프로젝트: kego/ke
// FromContext returns the User value stored in ctx, if any.
func FromContext(ctx context.Context) *Env {
	e, ok := ctx.Value(envKey).(*Env)
	if !ok {
		panic(kerr.New("WYDYAGVLCR", "No env in ctx").Error())
	}
	return e
}
예제 #19
0
파일: pattern.go 프로젝트: goji/goji
/*
Path returns the path that the Goji router uses to perform the PathPrefix
optimization. While this function does not distinguish between the absence of a
path and an empty path, Goji will automatically extract a path from the request
if none is present.

By convention, paths are stored in their escaped form (i.e., the value returned
by net/url.URL.EscapedPath, and not URL.Path) to ensure that Patterns have as
much discretion as possible (e.g., to behave differently for '/' and '%2f').
*/
func Path(ctx context.Context) string {
	pi := ctx.Value(internal.Path)
	if pi == nil {
		return ""
	}
	return pi.(string)
}
예제 #20
0
파일: envctx.go 프로젝트: kego/ke
func FromContextOrNil(ctx context.Context) *Env {
	e, ok := ctx.Value(envKey).(*Env)
	if ok {
		return e
	}
	return nil
}
예제 #21
0
파일: auth.go 프로젝트: z0rr0/luss
// ExtractTokenKey extracts user's  from from context.
func ExtractTokenKey(ctx context.Context) (string, error) {
	t, ok := ctx.Value(tokenKey).(string)
	if !ok {
		return "", errors.New("not found context token")
	}
	return t, nil
}
예제 #22
0
파일: core.go 프로젝트: z0rr0/luss
// TrackerChan extracts tracker channel.
func TrackerChan(ctx context.Context) (chan *CuInfo, error) {
	p, ok := ctx.Value(trackerKey).(chan *CuInfo)
	if !ok {
		return nil, errors.New("not found context tracker channel")
	}
	return p, nil
}
예제 #23
0
파일: cmdctx.go 프로젝트: kego/ke
func FromContextOrNil(ctx context.Context) *Cmd {
	e, ok := ctx.Value(cmdKey).(*Cmd)
	if ok {
		return e
	}
	return nil
}
예제 #24
0
파일: search.go 프로젝트: vmware/vic
func NewSearchFlag(ctx context.Context, t int) (*SearchFlag, context.Context) {
	if v := ctx.Value(searchFlagKey); v != nil {
		return v.(*SearchFlag), ctx
	}

	v := &SearchFlag{
		t: t,
	}

	v.ClientFlag, ctx = NewClientFlag(ctx)
	v.DatacenterFlag, ctx = NewDatacenterFlag(ctx)

	switch t {
	case SearchVirtualMachines:
		v.entity = "VM"
	case SearchHosts:
		v.entity = "host"
	case SearchVirtualApps:
		v.entity = "vapp"
	default:
		panic("invalid search type")
	}

	ctx = context.WithValue(ctx, searchFlagKey, v)
	return v, ctx
}
예제 #25
0
func RequestContextFromContext(ctx context.Context) *RequestContext {
	val := ctx.Value(requestContextCtxKey)
	if val == nil {
		return nil
	}
	return val.(*RequestContext)
}
예제 #26
0
func DeserializedBody(ctx context.Context, v interface{}) error {
	mw_rctx, ok := ctx.Value(requestContextCtxKey).(*requestContext)
	if !ok {
		return errors.New("Request did not pass through serializers middleware")
	}
	return mw_rctx.DeserializedBody(v)
}
예제 #27
0
파일: context.go 프로젝트: kego/ke
func FromContext(ctx context.Context) *App {
	app, ok := ctx.Value(ctxKey).(*App)
	if !ok {
		panic(kerr.New("EJRTLPWCKH", "No app in ctx").Error())
	}
	return app
}
예제 #28
0
파일: db.go 프로젝트: z0rr0/luss
// CtxSession finds and returns MongoDB session from the Context.
func CtxSession(ctx context.Context) (*mgo.Session, error) {
	s, ok := ctx.Value(sessionKey).(*mgo.Session)
	if !ok {
		return nil, errors.New("not found context db session")
	}
	return s, nil
}
예제 #29
0
파일: handler.go 프로젝트: rs/xstats
// FromContext retreives the request's xstats client from a given context if any.
// If no xstats is embeded in the context, a nop instance is returned so you can
// use it safely without having to test for it's presence.
func FromContext(ctx context.Context) XStater {
	rc, ok := ctx.Value(xstatsKey).(XStater)
	if ok {
		return rc
	}
	return nop
}
예제 #30
0
func OriginalDestinationFromContext(ctx context.Context) net.Destination {
	v := ctx.Value(originalDestinationKey)
	if v == nil {
		return net.Destination{}
	}
	return v.(net.Destination)
}