本文整理匯總了Golang中github.com/MiniProfiler/go/miniprofiler_gae.Context.Infof方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Infof方法的具體用法?Golang Context.Infof怎麽用?Golang Context.Infof使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MiniProfiler/go/miniprofiler_gae.Context
的用法示例。
在下文中一共展示了Context.Infof方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UpdateFeeds
func UpdateFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
q := datastore.NewQuery("F").KeysOnly().Filter("n <=", time.Now())
q = q.Limit(10 * 60 * 2) // 10/s queue, 2 min cron
it := q.Run(appengine.Timeout(c, time.Minute))
tc := make(chan *taskqueue.Task)
done := make(chan bool)
i := 0
u := routeUrl("update-feed")
go taskSender(c, "update-feed", tc, done)
for {
k, err := it.Next(nil)
if err == datastore.Done {
break
} else if err != nil {
c.Errorf("next error: %v", err.Error())
break
}
tc <- taskqueue.NewPOSTTask(u, url.Values{
"feed": {k.StringID()},
})
i++
}
close(tc)
<-done
c.Infof("updating %d feeds", i)
}
示例2: UpdateFeed
func UpdateFeed(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
url := r.FormValue("feed")
c.Debugf("update feed %s", url)
f := Feed{Url: url}
if err := gn.Get(&f); err == datastore.ErrNoSuchEntity {
return
} else if time.Now().Before(f.NextUpdate) {
c.Infof("feed %v already updated", url)
return
}
if feed, stories := fetchFeed(c, url, url); feed != nil {
updateFeed(c, url, feed, stories)
} else {
f.Errors++
v := f.Errors + 1
const max = 24 * 7
if v > max {
v = max
} else if f.Errors == 1 {
v = 0
}
f.NextUpdate = time.Now().Add(time.Hour * time.Duration(v))
gn.Put(&f)
c.Warningf("error with %v (%v), bump next update to %v", url, f.Errors, f.NextUpdate)
}
}
示例3: SubscribeCallback
func SubscribeCallback(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
vars := mux.Vars(r)
b, _ := base64.URLEncoding.DecodeString(vars["feed"])
f := Feed{Url: string(b)}
if err := gn.Get(&f); err != nil {
http.Error(w, "", http.StatusNotFound)
return
}
if r.Method == "GET" {
if r.FormValue("hub.mode") != "subscribe" || r.FormValue("hub.topic") != f.Url {
http.Error(w, "", http.StatusNotFound)
return
}
w.Write([]byte(r.FormValue("hub.challenge")))
i, _ := strconv.Atoi(r.FormValue("hub.lease_seconds"))
f.Subscribed = time.Now().Add(time.Second * time.Duration(i))
gn.Put(&f)
c.Debugf("subscribed: %v - %v", f.Url, f.Subscribed)
return
} else {
c.Infof("push: %v", f.Url)
defer r.Body.Close()
b, _ := ioutil.ReadAll(r.Body)
nf, ss := ParseFeed(c, f.Url, b)
err := updateFeed(c, f.Url, nf, ss)
if err != nil {
c.Errorf("push error: %v", err)
}
}
}
示例4: UpdateFeeds
func UpdateFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
q := datastore.NewQuery(gn.Key(&Feed{}).Kind()).KeysOnly()
q = q.Filter("n <=", time.Now()).Limit(3000)
it := gn.Run(q)
i := 0
for {
k, err := it.Next(nil)
if err == datastore.Done {
break
} else if err != nil {
c.Errorf("next error: %v", err.Error())
break
}
t := taskqueue.NewPOSTTask(routeUrl("update-feed"), url.Values{
"feed": {k.StringID()},
})
if _, err := taskqueue.Add(c, t, "update-feed"); err != nil {
c.Errorf("taskqueue error: %v", err.Error())
}
i++
}
c.Infof("updating %d feeds", i)
fmt.Fprintf(w, "updating %d feeds", i)
}
示例5: DeleteOldFeed
func DeleteOldFeed(c mpg.Context, w http.ResponseWriter, r *http.Request) {
g := goon.FromContext(c)
oldDate := time.Now().Add(-time.Hour * 24 * 90)
feed := Feed{Url: r.FormValue("f")}
if err := g.Get(&feed); err != nil {
c.Criticalf("err: %v", err)
return
}
if feed.LastViewed.After(oldDate) {
return
}
q := datastore.NewQuery(g.Kind(&Story{})).Ancestor(g.Key(&feed)).KeysOnly()
keys, err := q.GetAll(c, nil)
if err != nil {
c.Criticalf("err: %v", err)
return
}
q = datastore.NewQuery(g.Kind(&StoryContent{})).Ancestor(g.Key(&feed)).KeysOnly()
sckeys, err := q.GetAll(c, nil)
if err != nil {
c.Criticalf("err: %v", err)
return
}
keys = append(keys, sckeys...)
c.Infof("delete: %v - %v", feed.Url, len(keys))
err = g.DeleteMulti(keys)
if err != nil {
c.Criticalf("err: %v", err)
}
}
示例6: SubscribeFeed
func SubscribeFeed(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
f := Feed{Url: r.FormValue("feed")}
if err := gn.Get(&f); err != nil {
c.Errorf("%v: %v", err, f.Url)
serveError(w, err)
return
} else if f.IsSubscribed() {
return
}
u := url.Values{}
u.Add("hub.callback", f.PubSubURL())
u.Add("hub.mode", "subscribe")
u.Add("hub.verify", "sync")
fu, _ := url.Parse(f.Url)
fu.Fragment = ""
u.Add("hub.topic", fu.String())
req, err := http.NewRequest("POST", PUBSUBHUBBUB_HUB, strings.NewReader(u.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
cl := urlfetch.Client(c)
resp, err := cl.Do(req)
if err != nil {
c.Errorf("req error: %v", err)
} else if resp.StatusCode != 204 {
c.Errorf("resp: %v - %v", f.Url, resp.Status)
c.Errorf("%s", resp.Body)
} else {
c.Infof("subscribed: %v", f.Url)
}
}
示例7: UpdateFeeds
func UpdateFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
q := datastore.NewQuery(gn.Key(&Feed{}).Kind()).KeysOnly()
q = q.Filter("n <=", time.Now())
retry, _ := strconv.Atoi(r.FormValue("retry"))
c.Errorf("retry: %v", retry)
//* iterator
it := gn.Run(q)
i := 0
done := false
for {
k, err := it.Next(nil)
if err == datastore.Done {
done = true
break
} else if err != nil {
c.Errorf("next error: %v", err.Error())
break
}
t := taskqueue.NewPOSTTask(routeUrl("update-feed"), url.Values{
"feed": {k.StringID()},
})
if _, err := taskqueue.Add(c, t, "update-feed"); err != nil {
c.Errorf("taskqueue error: %v", err.Error())
}
i++
}
c.Infof("updating %d feeds", i)
fmt.Fprintf(w, "updating %d feeds", i)
if !done {
time.Sleep(time.Second * time.Duration(i) / 50) // sleep about the time it'll take to process them
t := taskqueue.NewPOSTTask("/tasks/update-feeds", url.Values{
"retry": {strconv.Itoa(retry + 1)},
})
if _, err := taskqueue.Add(c, t, "update-feeds"); err != nil {
c.Errorf("taskqueue update feeds error: %v", err.Error())
}
c.Errorf("ran update again")
fmt.Fprintf(w, "\nran update again")
}
//*/
/* get all
q = q.Limit(1000)
keys, _ := gn.GetAll(q, nil)
for _, k := range keys {
t := taskqueue.NewPOSTTask(routeUrl("update-feed"), url.Values{
"feed": {k.StringID()},
})
if _, err := taskqueue.Add(c, t, "update-feed"); err != nil {
c.Errorf("taskqueue error: %v", err.Error())
}
}
c.Infof("updating %d feeds", len(keys))
fmt.Fprintf(w, "updating %d feeds", len(keys))
//*/
}
示例8: UpdateFeeds
func UpdateFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
q := datastore.NewQuery(gn.Key(&Feed{}).Kind()).KeysOnly()
q = q.Filter("n <=", time.Now())
q = q.Limit(1000)
it := gn.Run(q)
var keys []*datastore.Key
var del []*datastore.Key
for {
k, err := it.Next(nil)
if err == datastore.Done {
break
} else if err != nil {
c.Errorf("next error: %v", err.Error())
break
} else if len(k.StringID()) == 0 {
del = append(del, k)
continue
}
keys = append(keys, k)
}
tasks := make([]*taskqueue.Task, len(keys))
for i, k := range keys {
tasks[i] = taskqueue.NewPOSTTask(routeUrl("update-feed"), url.Values{
"feed": {k.StringID()},
})
}
var ts []*taskqueue.Task
const taskLimit = 100
for len(tasks) > 0 {
if len(tasks) > taskLimit {
ts = tasks[:taskLimit]
tasks = tasks[taskLimit:]
} else {
ts = tasks
tasks = tasks[0:0]
}
if _, err := taskqueue.AddMulti(c, ts, "update-feed"); err != nil {
c.Errorf("taskqueue error: %v", err.Error())
}
}
c.Infof("updating %d feeds", len(keys))
if len(del) > 0 {
c.Errorf("attempt to delete %v feeds", len(del))
if err := gn.DeleteMulti(del); err != nil {
c.Errorf("delete error: %v", err.Error())
}
fmt.Fprintf(w, `<html><head><meta http-equiv="refresh" content="0"></head></html>`)
fmt.Fprintf(w, "attempt to delete %v feeds", len(del))
for _, k := range del {
fmt.Fprintf(w, "\n<br>%v", k)
}
}
fmt.Fprintf(w, "updating %d feeds", len(keys))
}
示例9: ClearFeeds
func ClearFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
if !isDevServer {
return
}
cu := user.Current(c)
gn := goon.FromContext(c)
done := make(chan bool)
go func() {
u := &User{Id: cu.ID}
defer func() { done <- true }()
ud := &UserData{Id: "data", Parent: gn.Key(u)}
if err := gn.Get(u); err != nil {
c.Errorf("user del err: %v", err.Error())
return
}
gn.Get(ud)
u.Read = time.Time{}
ud.Read = nil
ud.Opml = nil
gn.PutMany(u, ud)
c.Infof("%v cleared", u.Email)
}()
del := func(kind string) {
defer func() { done <- true }()
q := datastore.NewQuery(kind).KeysOnly()
keys, err := gn.GetAll(q, nil)
if err != nil {
c.Errorf("err: %v", err.Error())
return
}
if err := gn.DeleteMulti(keys); err != nil {
c.Errorf("err: %v", err.Error())
return
}
c.Infof("%v deleted", kind)
}
types := []interface{}{
&Feed{},
&Story{},
&StoryContent{},
&DateFormat{},
&Log{},
&UserOpml{},
}
for _, i := range types {
k := gn.Key(i).Kind()
go del(k)
}
for i := 0; i < len(types); i++ {
<-done
}
http.Redirect(w, r, routeUrl("main"), http.StatusFound)
}
示例10: SubscribeFeed
// Task used to subscribe a feed to push.
func SubscribeFeed(c mpg.Context, w http.ResponseWriter, r *http.Request) {
start := time.Now()
gn := goon.FromContext(c)
f := Feed{Url: r.FormValue("feed")}
fk := gn.Key(&f)
s := ""
defer func() {
gn.Put(&Log{
Parent: fk,
Id: time.Now().UnixNano(),
Text: "SubscribeFeed - start " + start.String() + " - f.sub " + f.Subscribed.String() + " - " + s,
})
}()
if err := gn.Get(&f); err != nil {
c.Errorf("%v: %v", err, f.Url)
serveError(w, err)
s += "err"
return
} else if f.IsSubscribed() {
s += "is subscribed"
return
}
u := url.Values{}
u.Add("hub.callback", f.PubSubURL())
u.Add("hub.mode", "subscribe")
u.Add("hub.verify", "sync")
fu, _ := url.Parse(f.Url)
fu.Fragment = ""
u.Add("hub.topic", fu.String())
req, err := http.NewRequest("POST", f.Hub, strings.NewReader(u.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
cl := &http.Client{
Transport: &urlfetch.Transport{
Context: c,
Deadline: time.Minute,
},
}
resp, err := cl.Do(req)
if err != nil {
c.Errorf("req error: %v", err)
} else if resp.StatusCode != http.StatusNoContent {
f.Subscribed = time.Now().Add(time.Hour * 48)
gn.Put(&f)
if resp.StatusCode != http.StatusConflict {
c.Errorf("resp: %v - %v", f.Url, resp.Status)
c.Errorf("%s", resp.Body)
}
s += "resp err"
} else {
c.Infof("subscribed: %v", f.Url)
s += "success"
}
}
示例11: UpdateFeeds
func UpdateFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
q := datastore.NewQuery(gn.Key(&Feed{}).Kind()).KeysOnly()
q = q.Filter("n <=", time.Now())
keys, _ := gn.GetAll(q, nil)
for _, k := range keys {
t := taskqueue.NewPOSTTask(routeUrl("update-feed"), url.Values{
"feed": {k.StringID()},
})
if _, err := taskqueue.Add(c, t, "update-feed"); err != nil {
c.Errorf("taskqueue error: %v", err.Error())
}
}
c.Infof("updating %d feeds", len(keys))
}
示例12: UpdateFeeds
func UpdateFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
q := datastore.NewQuery("F").KeysOnly()
q = q.Filter("n <=", time.Now())
q = q.Limit(3000)
var keys []*datastore.Key
it := q.Run(c)
retry := 0
for {
k, err := it.Next(nil)
if err != nil {
c.Errorf("next error: %v, retry: %v", err.Error(), retry)
if retry == 5 {
break
}
retry++
it = q.Run(c)
} else {
keys = append(keys, k)
}
}
if len(keys) == 0 {
c.Errorf("giving up")
return
}
tasks := make([]*taskqueue.Task, len(keys))
for i, k := range keys {
c.Infof("task: %v, %v", i, k)
tasks[i] = taskqueue.NewPOSTTask(routeUrl("update-feed"), url.Values{
"feed": {k.StringID()},
})
}
var ts []*taskqueue.Task
const taskLimit = 100
for len(tasks) > 0 {
if len(tasks) > taskLimit {
ts = tasks[:taskLimit]
tasks = tasks[taskLimit:]
} else {
ts = tasks
tasks = tasks[0:0]
}
if _, err := taskqueue.AddMulti(c, ts, "update-feed"); err != nil {
c.Errorf("taskqueue error: %v", err.Error())
}
}
c.Infof("updating %d feeds", len(keys))
}
示例13: addFeed
func addFeed(c mpg.Context, userid string, outline *OpmlOutline) error {
gn := goon.FromContext(c)
o := outline.Outline[0]
c.Infof("adding feed %v to user %s", o.XmlUrl, userid)
fu, ferr := url.Parse(o.XmlUrl)
if ferr != nil {
return ferr
}
fu.Fragment = ""
o.XmlUrl = fu.String()
f := Feed{Url: o.XmlUrl}
if err := gn.Get(&f); err == datastore.ErrNoSuchEntity {
if feed, stories, err := fetchFeed(c, o.XmlUrl, o.XmlUrl); err != nil {
return fmt.Errorf("could not add feed %s: %v", o.XmlUrl, err)
} else {
f = *feed
f.Updated = time.Time{}
f.Checked = f.Updated
f.NextUpdate = f.Updated
f.LastViewed = time.Now()
gn.Put(&f)
for _, s := range stories {
s.Created = s.Published
}
if err := updateFeed(c, f.Url, feed, stories, false, false, false); err != nil {
return err
}
o.XmlUrl = feed.Url
o.HtmlUrl = feed.Link
if o.Title == "" {
o.Title = feed.Title
}
}
} else if err != nil {
return err
} else {
o.HtmlUrl = f.Link
if o.Title == "" {
o.Title = f.Title
}
}
o.Text = ""
return nil
}
示例14: AdminUser
func AdminUser(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
q := datastore.NewQuery(gn.Kind(&User{})).Limit(1)
q = q.Filter("e =", r.FormValue("u"))
it := gn.Run(q)
var u User
ud := UserData{Id: "data"}
var h []Log
k, err := it.Next(&u)
if err != nil {
serveError(w, err)
return
}
ud.Parent = gn.Key(&u)
gn.Get(&ud)
until := r.FormValue("until")
if d, err := time.Parse("2006-01-02", until); err == nil {
u.Until = d
gn.Put(&u)
}
if o := []byte(r.FormValue("opml")); len(o) > 0 {
opml := Opml{}
if err := json.Unmarshal(o, &opml); err != nil {
serveError(w, err)
return
}
ud.Opml = o
if _, err := gn.Put(&ud); err != nil {
serveError(w, err)
return
}
c.Infof("opml updated")
}
q = datastore.NewQuery(gn.Kind(&Log{})).Ancestor(k)
_, err = gn.GetAll(q, &h)
if err := templates.ExecuteTemplate(w, "admin-user.html", struct {
User User
Data UserData
Log []Log
}{
u,
ud,
h,
}); err != nil {
serveError(w, err)
}
}
示例15: UpdateFeeds
func UpdateFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
q := datastore.NewQuery("F").KeysOnly().Filter("n <=", time.Now())
q = q.Limit(10 * 60 * 20) // 10/s queue, 20 min cron
var keys []*datastore.Key
it := q.Run(appengine.Timeout(c, time.Second*60))
for {
k, err := it.Next(nil)
if err == datastore.Done {
break
} else if err != nil {
c.Errorf("next error: %v", err.Error())
break
}
keys = append(keys, k)
}
if len(keys) == 0 {
c.Errorf("no results")
return
}
c.Infof("updating %d feeds", len(keys))
var tasks []*taskqueue.Task
for _, k := range keys {
tasks = append(tasks, taskqueue.NewPOSTTask(routeUrl("update-feed"), url.Values{
"feed": {k.StringID()},
}))
}
var ts []*taskqueue.Task
const taskLimit = 100
for len(tasks) > 0 {
if len(tasks) > taskLimit {
ts = tasks[:taskLimit]
tasks = tasks[taskLimit:]
} else {
ts = tasks
tasks = tasks[0:0]
}
if _, err := taskqueue.AddMulti(c, ts, "update-feed"); err != nil {
c.Errorf("taskqueue error: %v", err.Error())
}
}
}