本文整理匯總了Golang中github.com/MiniProfiler/go/miniprofiler_gae.Context.Errorf方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Errorf方法的具體用法?Golang Context.Errorf怎麽用?Golang Context.Errorf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MiniProfiler/go/miniprofiler_gae.Context
的用法示例。
在下文中一共展示了Context.Errorf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Main
func Main(c mpg.Context, w http.ResponseWriter, r *http.Request) {
if err := templates.ExecuteTemplate(w, "base.html", includes(c, w, r)); err != nil {
c.Errorf("%v", err)
serveError(w, err)
return
}
}
示例2: CFix
func CFix(c mpg.Context, w http.ResponseWriter, r *http.Request) {
gn := goon.FromContext(c)
url := r.FormValue("feed")
c.Infof("fix feed %s", url)
f := Feed{Url: url}
if err := gn.Get(&f); err != nil {
c.Criticalf("cfix err: %v", err)
serveError(w, err)
return
}
q := datastore.NewQuery("S").Ancestor(gn.Key(&f))
var ss []*Story
keys, err := q.GetAll(c, &ss)
if err != nil {
c.Errorf("getall err: %v", err)
serveError(w, err)
return
}
c.Infof("trying to fix %v stories", len(ss))
const putLimit = 500
for i := 0; i <= len(keys)/putLimit; i++ {
lo := i * putLimit
hi := (i + 1) * putLimit
if hi > len(keys) {
hi = len(keys)
}
c.Infof("%v - %v", lo, hi)
if _, err := datastore.PutMulti(c, keys[lo:hi], ss[lo:hi]); err != nil {
c.Errorf("err: %v, %v, %v", lo, hi, err)
}
}
}
示例3: AddSubscription
func AddSubscription(c mpg.Context, w http.ResponseWriter, r *http.Request) {
backupOPML(c)
cu := user.Current(c)
url := r.FormValue("url")
o := &OpmlOutline{
Outline: []*OpmlOutline{
&OpmlOutline{XmlUrl: url},
},
}
if err := addFeed(c, cu.ID, o); err != nil {
c.Errorf("add sub error (%s): %s", url, err.Error())
serveError(w, err)
return
}
gn := goon.FromContext(c)
ud := UserData{Id: "data", Parent: gn.Key(&User{Id: cu.ID})}
gn.Get(&ud)
if err := mergeUserOpml(c, &ud, o); err != nil {
c.Errorf("add sub error opml (%v): %v", url, err)
serveError(w, err)
return
}
gn.PutMany(&ud, &Log{
Parent: ud.Parent,
Id: time.Now().UnixNano(),
Text: fmt.Sprintf("add sub: %v", url),
})
if r.Method == "GET" {
http.Redirect(w, r, routeUrl("main"), http.StatusFound)
}
backupOPML(c)
}
示例4: Charge
func Charge(c mpg.Context, w http.ResponseWriter, r *http.Request) {
cu := user.Current(c)
gn := goon.FromContext(c)
u := User{Id: cu.ID}
uc := UserCharge{Id: 1, Parent: gn.Key(&u)}
if err := gn.Get(&u); err != nil {
serveError(w, err)
return
} else if u.Account != AFree {
serveError(w, fmt.Errorf("You're already subscribed."))
return
}
if err := gn.Get(&uc); err == nil && len(uc.Customer) > 0 {
serveError(w, fmt.Errorf("You're already subscribed."))
return
} else if err != datastore.ErrNoSuchEntity {
serveError(w, err)
return
}
resp, err := stripe(c, "POST", "customers", url.Values{
"email": {u.Email},
"description": {u.Id},
"card": {r.FormValue("stripeToken")},
"plan": {STRIPE_PLAN},
}.Encode())
if err != nil {
serveError(w, err)
return
} else if resp.StatusCode != http.StatusOK {
c.Errorf("%s", resp.Body)
serveError(w, fmt.Errorf("Error"))
return
}
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
var sc StripeCustomer
if err := json.Unmarshal(b, &sc); err != nil {
serveError(w, err)
return
}
if err := gn.RunInTransaction(func(gn *goon.Goon) error {
if err := gn.Get(&u); err != nil && err != datastore.ErrNoSuchEntity {
return err
}
if err := gn.Get(&uc); err != nil && err != datastore.ErrNoSuchEntity {
return err
}
u.Account = APaid
uc.Customer = sc.Id
uc.Last4 = sc.Card.Last4
uc.Created = time.Unix(sc.Created, 0)
_, err := gn.PutMany(&u, &uc)
return err
}, nil); err != nil {
serveError(w, err)
return
}
b, _ = json.Marshal(&uc)
w.Write(b)
}
示例5: doUncheckout
func doUncheckout(c mpg.Context) (*UserCharge, error) {
cu := user.Current(c)
gn := goon.FromContext(c)
u := User{Id: cu.ID}
uc := UserCharge{Id: 1, Parent: gn.Key(&u)}
if err := gn.Get(&u); err != nil {
return nil, err
}
if err := gn.Get(&uc); err != nil || len(uc.Customer) == 0 {
return nil, err
}
resp, err := stripe(c, "DELETE", "customers/"+uc.Customer, "")
if err != nil {
return nil, err
} else if resp.StatusCode != http.StatusOK {
c.Errorf("%s", resp.Body)
c.Errorf("stripe delete error, but proceeding")
}
if err := gn.RunInTransaction(func(gn *goon.Goon) error {
if err := gn.Get(&u); err != nil && err != datastore.ErrNoSuchEntity {
return err
}
u.Account = AFree
u.Until = uc.Next
if err := gn.Delete(gn.Key(&uc)); err != nil {
return err
}
_, err := gn.Put(&u)
return err
}, nil); err != nil {
return nil, err
}
return &uc, nil
}
示例6: UploadOpml
func UploadOpml(c mpg.Context, w http.ResponseWriter, r *http.Request) {
opml := Opml{}
if err := json.Unmarshal([]byte(r.FormValue("opml")), &opml.Outline); err != nil {
serveError(w, err)
return
}
backupOPML(c)
cu := user.Current(c)
gn := goon.FromContext(c)
u := User{Id: cu.ID}
ud := UserData{Id: "data", Parent: gn.Key(&u)}
if err := gn.Get(&ud); err != nil {
serveError(w, err)
c.Errorf("get err: %v", err)
return
}
if b, err := json.Marshal(&opml); err != nil {
serveError(w, err)
c.Errorf("json err: %v", err)
return
} else {
l := Log{
Parent: ud.Parent,
Id: time.Now().UnixNano(),
Text: fmt.Sprintf("upload opml: %v -> %v", len(ud.Opml), len(b)),
}
ud.Opml = b
if _, err := gn.PutMany(&ud, &l); err != nil {
serveError(w, err)
return
}
backupOPML(c)
}
}
示例7: FeedHistory
func FeedHistory(c mpg.Context, w http.ResponseWriter, r *http.Request) {
cu := user.Current(c)
gn := goon.FromContext(c)
u := User{Id: cu.ID}
uk := gn.Key(&u)
if v := r.FormValue("v"); len(v) == 0 {
q := datastore.NewQuery(gn.Key(&UserOpml{}).Kind()).Ancestor(uk).KeysOnly()
keys, err := gn.GetAll(q, nil)
if err != nil {
serveError(w, err)
return
}
times := make([]string, len(keys))
for i, k := range keys {
times[i] = strconv.FormatInt(k.IntID(), 10)
}
b, _ := json.Marshal(×)
w.Write(b)
} else {
a, _ := strconv.ParseInt(v, 10, 64)
uo := UserOpml{Id: a, Parent: uk}
c.Errorf("k: %v", uo)
if err := gn.Get(&uo); err != nil {
serveError(w, err)
return
}
downloadOpml(w, uo.opml(), cu.Email)
}
}
示例8: 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)
}
示例9: Donate
func Donate(c mpg.Context, w http.ResponseWriter, r *http.Request) {
cu := user.Current(c)
gn := goon.FromContext(c)
u := User{Id: cu.ID}
if err := gn.Get(&u); err != nil {
serveError(w, err)
return
}
amount, err := strconv.Atoi(r.FormValue("amount"))
if err != nil || amount < 200 {
serveError(w, fmt.Errorf("bad amount: %v", r.FormValue("amount")))
return
}
resp, err := stripe(c, "POST", "charges", url.Values{
"amount": {r.FormValue("amount")},
"description": {fmt.Sprintf("%v - %v", u.Id, u.Email)},
"card": {r.FormValue("stripeToken")},
"currency": {"usd"},
}.Encode())
if err != nil {
serveError(w, err)
return
} else if resp.StatusCode != http.StatusOK {
c.Errorf("%s", resp.Body)
serveError(w, fmt.Errorf("Error"))
return
}
}
示例10: UploadOpml
func UploadOpml(c mpg.Context, w http.ResponseWriter, r *http.Request) {
opml := Opml{}
if err := json.Unmarshal([]byte(r.FormValue("opml")), &opml.Outline); err != nil {
serveError(w, err)
return
}
backupOPML(c)
cu := user.Current(c)
gn := goon.FromContext(c)
u := User{Id: cu.ID}
ud := UserData{Id: "data", Parent: gn.Key(&u)}
if err := gn.Get(&ud); err != nil {
serveError(w, err)
c.Errorf("get err: %v", err)
return
}
if b, err := json.Marshal(&opml); err != nil {
saveError(c, fmt.Sprintf("%v", opml), err)
serveError(w, err)
c.Errorf("json err: %v", err)
return
} else {
ud.Opml = b
}
gn.Put(&ud)
backupOPML(c)
}
示例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()).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)
}
示例12: 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)
}
}
}
示例13: 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))
//*/
}
示例14: ImportOpml
func ImportOpml(c mpg.Context, w http.ResponseWriter, r *http.Request) {
cu := user.Current(c)
gn := goon.FromContext(c)
u := User{Id: cu.ID}
if err := gn.Get(&u); err != nil {
serveError(w, err)
return
}
backupOPML(c)
if file, _, err := r.FormFile("file"); err == nil {
if fdata, err := ioutil.ReadAll(file); err == nil {
buf := bytes.NewReader(fdata)
// attempt to extract from google reader takeout zip
if zb, zerr := zip.NewReader(buf, int64(len(fdata))); zerr == nil {
for _, f := range zb.File {
if strings.HasSuffix(f.FileHeader.Name, "Reader/subscriptions.xml") {
if rc, rerr := f.Open(); rerr == nil {
if fb, ferr := ioutil.ReadAll(rc); ferr == nil {
fdata = fb
break
}
}
}
}
}
// Preflight the OPML, so we can report any errors.
d := xml.NewDecoder(bytes.NewReader(fdata))
d.CharsetReader = charset.NewReader
d.Strict = false
opml := Opml{}
if err := d.Decode(&opml); err != nil {
serveError(w, err)
c.Errorf("opml error: %v", err.Error())
return
}
var b bytes.Buffer
enc := gob.NewEncoder(&b)
err := enc.Encode(&opml)
if err != nil {
serveError(w, err)
return
}
bk, err := saveFile(c, b.Bytes())
if err != nil {
serveError(w, err)
return
}
task := taskqueue.NewPOSTTask(routeUrl("import-opml-task"), url.Values{
"key": {string(bk)},
"user": {cu.ID},
})
taskqueue.Add(c, task, "import-reader")
}
}
}
示例15: SitemapFeed
func SitemapFeed(c mpg.Context, w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
feed := vars["feed"]
fk, err := datastore.DecodeKey(feed)
if err != nil {
serveError(w, err)
return
}
bf := base64.URLEncoding.EncodeToString([]byte(fk.StringID()))
q := datastore.NewQuery("S").KeysOnly().Ancestor(fk)
q = q.Limit(Limit)
cs := r.FormValue("c")
if len(cs) > 0 {
if cur, err := datastore.DecodeCursor(cs); err == nil {
q = q.Start(cur)
}
}
stories := make(map[string]string)
it := q.Run(c)
for {
k, err := it.Next(nil)
if err == datastore.Done {
break
} else if err != nil {
c.Errorf("next error: %v", err)
break
}
stories[k.StringID()] = base64.URLEncoding.EncodeToString([]byte(k.StringID()))
}
cs = ""
if len(stories) == Limit {
if cur, err := it.Cursor(); err == nil {
cs = cur.String()
}
}
if err := templates.ExecuteTemplate(w, "sitemap-feed.html", struct {
Feed, Feed64 string
Stories map[string]string
Cursor string
}{
Feed: feed,
Feed64: bf,
Stories: stories,
Cursor: cs,
}); err != nil {
c.Errorf("%v", err)
serveError(w, err)
return
}
}