本文整理汇总了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
}
示例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})
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例9: rawService
func rawService(ctx context.Context) *raw.Service {
return ctx.Value(internal.Key(0)).(map[string]interface{})["pubsub_service"].(*raw.Service)
}
示例10: projID
func projID(ctx context.Context) string {
return ctx.Value(internal.Key(0)).(map[string]interface{})["project_id"].(string)
}
示例11: FromContext
func FromContext(ctx context.Context) (RequestID, bool) {
reqID, ok := ctx.Value(reqIDKey).(RequestID)
return reqID, ok
}
示例12: ContextualTwo
func ContextualTwo(ctx context.Context, rw http.ResponseWriter, r *http.Request) {
message := ctx.Value(key).(string)
rw.Write([]byte(message))
}
示例13: FromContext
// FromContext returns the pool assigned to the context.
func FromContext(c context.Context) *PubSub {
return c.Value(reqkey).(*PubSub)
}
示例14: FromContext
// FromContext returns the Blobstore associated with this context.
func FromContext(c context.Context) Blobstore {
return c.Value(reqkey).(Blobstore)
}
示例15: FromContext
// FromContext returns the pool assigned to the context.
func FromContext(c context.Context) *Pool {
return c.Value(reqkey).(*Pool)
}