本文整理汇总了Golang中google/golang.org/appengine/log.Debugf函数的典型用法代码示例。如果您正苦于以下问题:Golang Debugf函数的具体用法?Golang Debugf怎么用?Golang Debugf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debugf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdateAllPortfoliosAndAlert
func UpdateAllPortfoliosAndAlert(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
if len(cachedStocks) == 0 {
log.Debugf(ctx, "UpdateAllPortfoliosAndAlert: cachedStocks are empty")
return
}
if !isWeekDay() {
log.Debugf(ctx, "UpdateAllPortfoliosAndAlert: is not a weekday.")
return
}
defer func() { isUpdateInProgress = false }()
isUpdateInProgress = true
var portfolioStocks []PortfolioStock
if err := GetAllEntities(ctx, "PortfolioStock", &portfolioStocks); err != nil {
log.Debugf(ctx, "UpdateAllPortfoliosAndAlert: Could not fetch all portfolios ", err)
return
}
if len(portfolioStocks) == 0 {
log.Debugf(ctx, "UpdateAllPortfoliosAndAlert: fetched portfoilios len is 0")
return
}
// log.Debugf(ctx,"Before filteting eligible stocks ", Jsonify(portfolioStocks))
eligibleStocks := FilterForAlertEligiblePortfolioStocks(ctx, portfolioStocks)
// log.Debugf(ctx,"After filteting eligible stocks ", Jsonify(portfolioStocks))
SendAlerts(ctx, eligibleStocks)
}
示例2: writeLogStorage
func (sink *LogSink) writeLogStorage(r *wcg.LogRecord) error {
c := sink.ctx
formatter := sink.formatter
if c == nil {
c = NewContext(r.Request)
}
var text string
if r.SourceStack != nil && len(r.SourceStack) > 0 {
text = fmt.Sprintf(
"%s\n-- Stack Trace --\n%s",
string(formatter.Format(r)),
strings.Join(r.SourceStack, "\n"),
)
} else {
text = string(formatter.Format(r))
}
switch r.Level {
case wcg.LogLevelTrace:
log.Debugf(c, "%s", text) // app engine does not support trace level
case wcg.LogLevelDebug:
log.Debugf(c, "%s", text)
case wcg.LogLevelInfo:
log.Infof(c, "%s", text)
case wcg.LogLevelWarn:
log.Warningf(c, "%s", text)
case wcg.LogLevelError:
log.Errorf(c, "%s", text)
case wcg.LogLevelFatal:
log.Criticalf(c, "%s", text)
default:
// nothing
}
return nil
}
示例3: ajaxAboutAllIdioms
func ajaxAboutAllIdioms(w http.ResponseWriter, r *http.Request) error {
c := appengine.NewContext(r)
log.Debugf(c, "retrieveAllIdioms start...")
allIdioms, err := retrieveAllIdioms(r)
if err != nil {
return err
}
log.Debugf(c, "retrieveAllIdioms end.")
data := AboutFacade{
PageMeta: PageMeta{
Toggles: toggles,
},
UserProfile: readUserProfile(r),
AllIdioms: allIdioms,
}
log.Debugf(c, "block-about-all-idioms templating start...")
if err := templates.ExecuteTemplate(w, "block-about-all-idioms", data); err != nil {
return PiError{err.Error(), http.StatusInternalServerError}
}
log.Debugf(c, "block-about-all-idioms templating end.")
return nil
}
示例4: handlePostMessage
func (api *API) handlePostMessage(res http.ResponseWriter, req *http.Request) error {
ctx := appengine.NewContext(req)
// handle incoming messages, send them out to everyone
type Post struct {
Text string
}
var post Post
// post := struct{
// Text string
// }{}
err := json.NewDecoder(req.Body).Decode(&post)
if err != nil {
return err
}
log.Debugf(ctx, "the post is %s", post.Text)
query := datastore.NewQuery("connections")
it := query.Run(ctx)
for {
var connection struct{ Email string }
_, err := it.Next(&connection)
if err == datastore.Done {
break
} else if err != nil {
return err
}
log.Debugf(ctx, "here is the email %s", connection.Email)
err = channel.SendJSON(ctx, connection.Email, post)
if err != nil {
return err
}
}
return nil
}
示例5: CurrentUser
// CurrentUser checks for both JWT and Bearer tokens.
//
// It first tries to decode and verify JWT token (if conditions are met)
// and falls back to Bearer token.
//
// The returned user will have only ID, Email and ClientID fields set.
// User.ID is a Google Account ID, which is different from GAE user ID.
// For more info on User.ID see 'sub' claim description on
// https://developers.google.com/identity/protocols/OpenIDConnect#obtainuserinfo
func CurrentUser(c context.Context, scopes []string, audiences []string, clientIDs []string) (*user.User, error) {
// The user hasn't provided any information to allow us to parse either
// an ID token or a Bearer token.
if len(scopes) == 0 && len(audiences) == 0 && len(clientIDs) == 0 {
return nil, errors.New("no client ID or scope info provided.")
}
r := HTTPRequest(c)
if r == nil {
return nil, errNoRequest
}
token := parseToken(r)
if token == "" {
return nil, errors.New("No token in the current context.")
}
// If the only scope is the email scope, check an ID token. Alternatively,
// we dould check if token starts with "ya29." or "1/" to decide that it
// is a Bearer token. This is what is done in Java.
if len(scopes) == 1 && scopes[0] == EmailScope && len(clientIDs) > 0 {
log.Debugf(c, "Checking for ID token.")
now := currentUTC().Unix()
u, err := currentIDTokenUser(c, token, audiences, clientIDs, now)
// Only return in case of success, else pass along and try
// parsing Bearer token.
if err == nil {
return u, err
}
}
log.Debugf(c, "Checking for Bearer token.")
return CurrentBearerTokenUser(c, scopes, clientIDs)
}
示例6: buildSlackJSON
// buildSlackJSON returns a public or private Slack JSON response as a byte slice.
// Context is passed in for logging.
func buildSlackJSON(ctx context.Context, text string, isPublic bool) ([]byte, error) {
// JustinResponse is a response we send back to Slack
type JustinResponse struct {
ResponseType string `json:"response_type"` // "ephemeral" (private) or "in_channel" (public)
Text string `json:"text"`
}
justinResponse := &JustinResponse{
Text: text,
}
if isPublic {
justinResponse.ResponseType = "in_channel"
} else {
justinResponse.ResponseType = "ephemeral"
}
log.Debugf(ctx, "Marshalling JustinResponse: %#v", justinResponse)
justinJSON, err := json.Marshal(justinResponse)
if err != nil {
log.Errorf(ctx, "Error marshalling JSON for JustinResponse: %#v - %s", justinResponse, err)
return nil, err
}
log.Debugf(ctx, "Slack response: %s", string(justinJSON))
return justinJSON, nil
}
示例7: fetchTokeninfo
// fetchTokeninfo retrieves token info from tokeninfoEndpointURL (tokeninfo API)
func fetchTokeninfo(c context.Context, token string) (*tokeninfo, error) {
url := tokeninfoEndpointURL + "?access_token=" + token
log.Debugf(c, "Fetching token info from %q", url)
resp, err := newHTTPClient(c).Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
log.Debugf(c, "Tokeninfo replied with %s", resp.Status)
ti := &tokeninfo{}
if err = json.NewDecoder(resp.Body).Decode(ti); err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("Error fetching tokeninfo (status %d)", resp.StatusCode)
if ti.ErrorDescription != "" {
errMsg += ": " + ti.ErrorDescription
}
return nil, errors.New(errMsg)
}
switch {
case ti.ExpiresIn <= 0:
return nil, errors.New("Token is expired")
case !ti.VerifiedEmail:
return nil, fmt.Errorf("Unverified email %q", ti.Email)
case ti.Email == "":
return nil, fmt.Errorf("Invalid email address")
}
return ti, err
}
示例8: clearLock
// clearLock clears the current lease, it should be called at the end of every task
// execution if things fail, to try and prevent unecessary locks and to count the
// number of retries
func (l *Locker) clearLock(c context.Context, key *datastore.Key, entity Lockable) error {
lock := entity.getLock()
if lock.Retries == l.MaxRetries {
if l.AlertOnFailure {
if err := alertAdmins(c, key, entity, "Permanent task failure"); err != nil {
log.Errorf(c, "failed to send alert email for permanent task failure: %v", err)
}
}
return ErrTaskFailed
}
err := storage.RunInTransaction(c, func(tc context.Context) error {
if err := storage.Get(tc, key, entity); err != nil {
log.Debugf(c, "clearLock get %v", err)
return err
}
lock := entity.getLock()
lock.Timestamp = getTime()
lock.RequestID = ""
lock.Retries++
if _, err := storage.Put(tc, key, entity); err != nil {
log.Debugf(c, "clearLock put %v", err)
return err
}
return nil
}, nil)
return err
}
示例9: cacheSameValues
func (a *MemcacheDatastoreAccessor) cacheSameValues(c context.Context, cacheKeys []string, data interface{}, expiration time.Duration) error {
N := len(cacheKeys)
var buffer bytes.Buffer
enc := gob.NewEncoder(&buffer)
err := enc.Encode(&data)
if err != nil {
log.Debugf(c, "Failed encoding for cache keys [%v] : %v", cacheKeys, err)
return err
}
items := make([]*memcache.Item, N)
for i, cacheKey := range cacheKeys {
cacheItem := &memcache.Item{
Key: cacheKey,
Value: buffer.Bytes(),
Expiration: expiration,
}
items[i] = cacheItem
}
// Set the items, unconditionally, in 1 batch call
err = memcache.SetMulti(c, items)
if err != nil {
log.Debugf(c, "Failed setting cache items: %v", cacheKeys, err)
}
return err
}
示例10: cacheValues
func (a *MemcacheDatastoreAccessor) cacheValues(c context.Context, cacheKeys []string, data []interface{}, expiration time.Duration) error {
if len(cacheKeys) != len(data) {
panic(fmt.Errorf("Wrong params length", len(cacheKeys), len(data)))
}
N := len(cacheKeys)
var buffer bytes.Buffer
enc := gob.NewEncoder(&buffer)
items := make([]*memcache.Item, N)
for i, cacheKey := range cacheKeys {
cacheData := data[i]
err := enc.Encode(&cacheData)
if err != nil {
log.Debugf(c, "Failed encoding for cache[%v] : %v", cacheKey, err)
return err
}
cacheItem := &memcache.Item{
Key: cacheKey,
Value: buffer.Bytes(),
Expiration: expiration,
}
items[i] = cacheItem
}
// Set the items, unconditionally, in 1 batch call
err := memcache.SetMulti(c, items)
if err != nil {
log.Debugf(c, "Failed setting cache items: %v", cacheKeys, err)
}
return err
}
示例11: commitBoardState
func commitBoardState(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
log.Debugf(c, "Commit Board State received!", nil)
if r.Method != "POST" {
http.Error(w, "Invalid method.", 500)
return
}
dec := json.NewDecoder(r.Body)
defer r.Body.Close()
state := &BoardState{}
err := dec.Decode(&state)
if err != nil {
http.Error(w, fmt.Sprintf("Failed to parse board state. %s", err.Error()), 500)
return
}
log.Debugf(c, "Input: %v", state)
newState, err := SaveGame(c, state)
if err != nil {
http.Error(w, fmt.Sprintf("Failed to save board state. %s", err.Error()), 500)
return
}
enc := json.NewEncoder(w)
err = enc.Encode(newState)
if err != nil {
http.Error(w, fmt.Sprintf("Failed to parse board state response. %s", err.Error()), 500)
return
}
}
示例12: sendUpdate
func sendUpdate(ctx context.Context, g *Game) {
fb, err := firebase(ctx)
if err != nil {
log.Errorf(ctx, "getFirebase: %v", err)
}
chans := fb.Child("channels")
gameKey := g.K.Encode()
if g.UserO != "" {
channelID := g.UserO + gameKey
if err := chans.Child(channelID).Set(g); err != nil {
log.Errorf(ctx, "Updating UserO (%s): %v", channelID, err)
} else {
log.Debugf(ctx, "Update O sent.")
}
}
if g.UserX != "" {
channelID := g.UserX + gameKey
if err := chans.Child(channelID).Set(g); err != nil {
log.Errorf(ctx, "Updating UserX (%s): %v", channelID, err)
} else {
log.Debugf(ctx, "Update X sent.")
}
}
}
示例13: SendAlerts
func SendAlerts(ctx context.Context, stocksForAlert []PortfolioStock) {
if len(stocksForAlert) == 0 {
log.Debugf(ctx, "SendAlerts: Alert stocks are empty")
return
}
//group by user emails to send a consolidated email
groupedStockAlerts := make(map[string][]PortfolioStock)
for _, alert := range stocksForAlert {
userPortfolioStocks := groupedStockAlerts[alert.Email]
userPortfolioStocks = append(userPortfolioStocks, alert)
groupedStockAlerts[alert.Email] = userPortfolioStocks
}
log.Debugf(ctx, "Will send alerts for ", Jsonify(groupedStockAlerts))
for email, alerts := range groupedStockAlerts {
msg := &mail.Message{
Sender: "NewTechFellas Stock Alerts <[email protected]>",
To: []string{email},
Subject: "Newtechfellas stock alerts for your stocks - " + DateString(),
Body: getStocksAlertMailBody(alerts),
}
if err := mail.Send(ctx, msg); err != nil {
log.Debugf(ctx, "Couldn't send email: %v", err)
}
}
for _, portfolioStock := range stocksForAlert {
portfolioStock.AlertSentTime = time.Now()
//Save stocksForAlert to update last alert sent time
CreateOrUpdate(ctx, &portfolioStock, portfolioStock.kind(), portfolioStock.stringId(), 0)
}
}
示例14: cachedCerts
// cachedCerts fetches public certificates info from DefaultCertURI and
// caches it for the duration specified in Age header of a response.
func cachedCerts(c context.Context) (*certsList, error) {
namespacedContext, err := appengine.Namespace(c, certNamespace)
if err != nil {
return nil, err
}
var certs *certsList
_, err = memcache.JSON.Get(namespacedContext, DefaultCertURI, &certs)
if err == nil {
return certs, nil
}
// Cache miss or server error.
// If any error other than cache miss, it's proably not a good time
// to use memcache.
var cacheResults = err == memcache.ErrCacheMiss
if !cacheResults {
log.Debugf(c, "%s", err.Error())
}
log.Debugf(c, "Fetching provider certs from: %s", DefaultCertURI)
resp, err := newHTTPClient(c).Get(DefaultCertURI)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, errors.New("Could not reach Cert URI or bad response.")
}
certBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(certBytes, &certs)
if err != nil {
return nil, err
}
if cacheResults {
expiration := certExpirationTime(resp.Header)
if expiration > 0 {
item := &memcache.Item{
Key: DefaultCertURI,
Value: certBytes,
Expiration: expiration,
}
err = memcache.Set(namespacedContext, item)
if err != nil {
log.Errorf(c, "Error adding Certs to memcache: %v", err)
}
}
}
return certs, nil
}
示例15: GetValidUser
func GetValidUser(email string, ctx context.Context, w http.ResponseWriter, r *http.Request) (user User, err error) {
//Is user verified
if err = GetEntity(ctx, email, 0, "User", &user); err != nil {
log.Debugf(ctx, "User not found for email ", email)
return
}
if !user.IsVerified {
log.Debugf(ctx, "User ", email, " is not verified")
ErrorResponse(w, errors.New("User is not verified. Check your email to confirm the registration"), http.StatusBadRequest)
return
}
return
}