Пример #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
// 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
// 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
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
/*
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
/*
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
// 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
/*
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
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
// 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)
}