当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Value方法代码示例

本文整理汇总了Golang中code/google/com/p/go/net/context.Context.Value方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Value方法的具体用法?Golang Context.Value怎么用?Golang Context.Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code/google/com/p/go/net/context.Context的用法示例。


在下文中一共展示了Context.Value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: HTTPRequest

// HTTPRequest returns the *http.Request associated with ctx using NewContext,
// if any.
func HTTPRequest(ctx context.Context) (*http.Request, bool) {
	// We cannot use ctx.(*wrapper).req to get the request because ctx may
	// be a Context derived from a *wrapper. Instead, we use Value to
	// access the request if it is anywhere up the Context tree.
	req, ok := ctx.Value(reqKey).(*http.Request)
	return req, ok
}
开发者ID:htee,项目名称:htee,代码行数:9,代码来源:context.go

示例2: SetProfileImage

func (handler *HomeWebserviceHandler) SetProfileImage(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	user := ctx.Value(KeyUser).(*usecases.User)

	imgData, hndl, err := r.FormFile("File")
	if err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	handler.Webservice.Log(fmt.Sprintf("Upload file %s", hndl.Filename))

	image, err := handler.ImageUtils.Load(imgData)
	if err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	image = handler.ImageUtils.Resize(image, 192, 192)

	data, err := handler.ImageUtils.Save(image, ".png")

	err = handler.FileStore.Create(fmt.Sprintf("upload/profile_%d.png", user.Id), data)
	if err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	if err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	handler.Webservice.SendJson(w, setProfileImageResponse{Result: true})
}
开发者ID:janicduplessis,项目名称:projectgo,代码行数:34,代码来源:homewebservice.go

示例3: NewReader

// NewReader creates a new io.ReadCloser to read the contents
// of the object.
func NewReader(ctx context.Context, bucket, name string) (io.ReadCloser, error) {
	c := ctx.Value(internal.Key(0)).(map[string]interface{})["http_client"].(*http.Client)
	resp, err := c.Get(fmt.Sprintf(templURLMedia, bucket, name))
	if err != nil {
		return nil, err
	}
	if resp.StatusCode == http.StatusNotFound {
		return nil, ErrObjectNotExists
	}
	return resp.Body, nil
}
开发者ID:qwo,项目名称:abelana-gcp,代码行数:13,代码来源:storage.go

示例4: RemoteAddr

// RemoteAddr accesses the remote address of the rpcwrap call connection in this context.
func RemoteAddr(ctx context.Context) (addr string, ok bool) {
	val := ctx.Value(remoteAddrKey)
	if val == nil {
		return "", false
	}
	addr, ok = val.(string)
	if !ok {
		return "", false
	}
	return addr, true
}
开发者ID:henryanand,项目名称:vitess,代码行数:12,代码来源:proto.go

示例5: Username

// Username accesses the authenticated username of the rpcwrap call connection in this context.
func Username(ctx context.Context) (user string, ok bool) {
	val := ctx.Value(usernameKey)
	if val == nil {
		return "", false
	}
	user, ok = val.(string)
	if !ok {
		return "", false
	}
	return user, ok
}
开发者ID:henryanand,项目名称:vitess,代码行数:12,代码来源:proto.go

示例6: SetUsername

// SetUsername sets the authenticated username associated with the rpcwrap call connection for this context.
// NOTE: For internal use by the rpcwrap library only. Contexts are supposed to be readonly, and
// this somewhat circumvents this intent.
func SetUsername(ctx context.Context, username string) (ok bool) {
	val := ctx.Value(usernameSlotKey)
	if val == nil {
		return false
	}
	slot, ok := val.(*string)
	if !ok {
		return false
	}
	*slot = username
	return true
}
开发者ID:henryanand,项目名称:vitess,代码行数:15,代码来源:proto.go

示例7: Logout

func (handler *AuthentificationWebserviceHandler) Logout(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	user := ctx.Value(KeyUser).(*usecases.User)

	if err := handler.ChatInteractor.Disconnect(user.Id); err != nil {
		handler.Webservice.Error(w, err)
		return
	}

	handler.Webservice.EndSession(ctx, w, r)

	reponse := &LogoutResponseModel{
		Result: true,
	}

	handler.Webservice.SendJson(w, reponse)
}
开发者ID:janicduplessis,项目名称:projectgo,代码行数:16,代码来源:authentificationwebservice.go

示例8: GetProfileModel

func (handler *HomeWebserviceHandler) GetProfileModel(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	user := ctx.Value(KeyUser).(*usecases.User)
	client, err := handler.HomeInteractor.GetClient(user.Id)
	if err != nil {
		handler.Webservice.Error(w, err)
	}

	model := &profileModel{
		Username:     user.Username,
		DisplayName:  client.DisplayName,
		FirstName:    client.FirstName,
		LastName:     client.LastName,
		Email:        client.Email,
		ProfileImage: fmt.Sprintf("/getProfileImage?clientId=%d", client.Id),
	}
	response := ModelResponse{
		Model: model,
	}
	handler.Webservice.SendJson(w, response)
}
开发者ID:janicduplessis,项目名称:projectgo,代码行数:20,代码来源:homewebservice.go

示例9: rawService

func rawService(ctx context.Context) *raw.Service {
	return ctx.Value(internal.Key(0)).(map[string]interface{})["pubsub_service"].(*raw.Service)
}
开发者ID:qwo,项目名称:abelana-gcp,代码行数:3,代码来源:pubsub.go

示例10: projID

func projID(ctx context.Context) string {
	return ctx.Value(internal.Key(0)).(map[string]interface{})["project_id"].(string)
}
开发者ID:qwo,项目名称:abelana-gcp,代码行数:3,代码来源:pubsub.go

示例11: FromContext

func FromContext(ctx context.Context) (RequestID, bool) {
	reqID, ok := ctx.Value(reqIDKey).(RequestID)
	return reqID, ok
}
开发者ID:shalecraig,项目名称:livegrep,代码行数:4,代码来源:reqid.go

示例12: ContextualTwo

func ContextualTwo(ctx context.Context, rw http.ResponseWriter, r *http.Request) {
	message := ctx.Value(key).(string)
	rw.Write([]byte(message))
}
开发者ID:CoreyKaylor,项目名称:gonion,代码行数:4,代码来源:contextual_test.go

示例13: FromContext

// FromContext returns the pool assigned to the context.
func FromContext(c context.Context) *PubSub {
	return c.Value(reqkey).(*PubSub)
}
开发者ID:carnivalmobile,项目名称:drone,代码行数:4,代码来源:context.go

示例14: FromContext

// FromContext returns the Blobstore associated with this context.
func FromContext(c context.Context) Blobstore {
	return c.Value(reqkey).(Blobstore)
}
开发者ID:Guoshusheng,项目名称:drone-dart,代码行数:4,代码来源:context.go

示例15: FromContext

// FromContext returns the pool assigned to the context.
func FromContext(c context.Context) *Pool {
	return c.Value(reqkey).(*Pool)
}
开发者ID:carnivalmobile,项目名称:drone,代码行数:4,代码来源:context.go


注:本文中的code/google/com/p/go/net/context.Context.Value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。