當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.Errorf方法代碼示例

本文整理匯總了Golang中google/golang.org/appengine.Context.Errorf方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Errorf方法的具體用法?Golang Context.Errorf怎麽用?Golang Context.Errorf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google/golang.org/appengine.Context的用法示例。


在下文中一共展示了Context.Errorf方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Call

// Call invokes a delayed function.
//   f.Call(c, ...)
// is equivalent to
//   t, _ := f.Task(...)
//   taskqueue.Add(c, t, "")
func (f *Function) Call(c appengine.Context, args ...interface{}) {
    t, err := f.Task(args...)
    if err != nil {
        c.Errorf("%v", err)
        return
    }
    if _, err := taskqueueAdder(c, t, queue); err != nil {
        c.Errorf("delay: taskqueue.Add failed: %v", err)
        return
    }
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:16,代碼來源:delay.go

示例2: makeAppEngineTokenFetcher

// FetchToken fetches a new access token for the provided scopes.
// Tokens are cached locally and also with Memcache so that the app can scale
// without hitting quota limits by calling appengine.AccessToken too frequently.
func makeAppEngineTokenFetcher(ctx appengine.Context, opts *oauth2.Options) func(*oauth2.Token) (*oauth2.Token, error) {
    return func(existing *oauth2.Token) (*oauth2.Token, error) {
        mu.Lock()
        defer mu.Unlock()

        key := ":" + strings.Join(opts.Scopes, "_")
        now := time.Now().Add(safetyMargin)
        if t, ok := tokens[key]; ok && !t.Expiry.Before(now) {
            return t, nil
        }
        delete(tokens, key)

        // Attempt to get token from Memcache
        tok := new(oauth2.Token)
        _, err := memcacheGob.Get(ctx, key, tok)
        if err == nil && !tok.Expiry.Before(now) {
            tokens[key] = tok // Save token locally
            return tok, nil
        }

        token, expiry, err := accessTokenFunc(ctx, opts.Scopes...)
        if err != nil {
            return nil, err
        }
        t := &oauth2.Token{
            AccessToken: token,
            Expiry:      expiry,
        }
        tokens[key] = t
        // Also back up token in Memcache
        if err = memcacheGob.Set(ctx, &memcache.Item{
            Key:        key,
            Value:      []byte{},
            Object:     *t,
            Expiration: expiry.Sub(now),
        }); err != nil {
            ctx.Errorf("unexpected memcache.Set error: %v", err)
        }
        return t, nil
    }
}
開發者ID:maxwhale,項目名稱:docker-gogs-centos,代碼行數:44,代碼來源:appenginevm.go

示例3: runFunc

func runFunc(c appengine.Context, w http.ResponseWriter, req *http.Request) {
    defer req.Body.Close()

    var inv invocation
    if err := gob.NewDecoder(req.Body).Decode(&inv); err != nil {
        c.Errorf("delay: failed decoding task payload: %v", err)
        c.Warningf("delay: dropping task")
        return
    }

    f := funcs[inv.Key]
    if f == nil {
        c.Errorf("delay: no func with key %q found", inv.Key)
        c.Warningf("delay: dropping task")
        return
    }

    ft := f.fv.Type()
    in := []reflect.Value{reflect.ValueOf(c)}
    for _, arg := range inv.Args {
        var v reflect.Value
        if arg != nil {
            v = reflect.ValueOf(arg)
        } else {
            // Task was passed a nil argument, so we must construct
            // the zero value for the argument here.
            n := len(in) // we're constructing the nth argument
            var at reflect.Type
            if !ft.IsVariadic() || n < ft.NumIn()-1 {
                at = ft.In(n)
            } else {
                at = ft.In(ft.NumIn() - 1).Elem()
            }
            v = reflect.Zero(at)
        }
        in = append(in, v)
    }
    out := f.fv.Call(in)

    if n := ft.NumOut(); n > 0 && ft.Out(n-1) == errorType {
        if errv := out[n-1]; !errv.IsNil() {
            c.Errorf("delay: func failed (will retry): %v", errv.Interface())
            w.WriteHeader(http.StatusInternalServerError)
            return
        }
    }
}
開發者ID:hortonworks,項目名稱:kubernetes-yarn,代碼行數:47,代碼來源:delay.go


注:本文中的google/golang.org/appengine.Context.Errorf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。