本文整理匯總了Golang中github.com/garyburd/twister/web.Request.Error方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Error方法的具體用法?Golang Request.Error怎麽用?Golang Request.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/garyburd/twister/web.Request
的用法示例。
在下文中一共展示了Request.Error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: serveSymbol
func serveSymbol(req *web.Request) {
var p []byte
if req.Method == "POST" {
var err os.Error
p, err = req.BodyBytes(-1)
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
} else {
p = []byte(req.URL.RawQuery)
}
w := respondText(req)
io.WriteString(w, "num_symbols: 1\n")
for len(p) > 0 {
var a []byte
if i := bytes.IndexByte(p, '+'); i >= 0 {
a = p[:i]
p = p[i+1:]
} else {
a = p
p = nil
}
if pc, _ := strconv.Btoui64(string(a), 0); pc != 0 {
if f := runtime.FuncForPC(uintptr(pc)); f != nil {
fmt.Fprintf(w, "%#x %s\n", pc, f.Name())
}
}
}
}
示例2: authCallbackHandler
// authCallbackHandler handles redirect from Facebook OAuth2 authorization page.
func authCallbackHandler(req *web.Request) {
code := req.Param.Get("code")
if code == "" {
// should display error_reason
req.Redirect("/", false)
return
}
f, err := getUrlEncodedForm("https://graph.facebook.com/oauth/access_token",
web.NewValues(
"client_id", appID, // defined in settings.go
"client_secret", appSecret, // defined in settings.go
"redirect_uri", req.URL.Scheme+"://"+req.URL.Host+"/callback",
"code", code))
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
token := f.Get("access_token")
expires := f.Get("expires")
if expires == "" {
expires = "3600"
}
maxAge, err := strconv.Atoi(expires)
if err != nil {
maxAge = 3600
} else {
maxAge -= 30 // fudge
}
req.Redirect("/", false,
web.HeaderSetCookie, web.NewCookie("fbtok", token).
MaxAge(maxAge-30).String())
}
示例3: Run
// Run simply runs the generator.
func (c *DummyCache) Run(req *web.Request, fnGenerate func(w io.Writer) bool) {
var buf = &bytes.Buffer{}
if fnGenerate(buf) {
req.Respond(web.StatusOK, web.HeaderContentType, "text/html").Write(buf.Bytes())
} else {
req.Error(web.StatusNotFound, os.NewError("Not Found."))
}
}
示例4: pathHandler
func pathHandler(req *web.Request, targetPattern string) {
if newPath := req.Param.Get("path"); newPath == "" {
req.Error(web.StatusNotFound, os.NewError("Not Found."))
} else {
newUrl := fmt.Sprintf(targetPattern, req.URL.Scheme, req.URL.Host, newPath)
req.Redirect(newUrl, true)
}
}
示例5: ServeWeb
func ServeWeb(req *web.Request) {
b, err := json.MarshalIndent(vars, "", " ")
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
req.Respond(web.StatusOK, web.HeaderContentType, "application/json; charset=utf-8").Write(b)
}
示例6: login
// login redirects the user to the Twitter authorization page.
func login(req *web.Request) {
callback := req.URL.Scheme + "://" + req.URL.Host + "/callback"
temporaryCredentials, err := oauthClient.RequestTemporaryCredentials(http.DefaultClient, callback)
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
req.Redirect(oauthClient.AuthorizationURL(temporaryCredentials), false,
web.HeaderSetCookie, credentialsCookie("tmp", temporaryCredentials, 0))
}
示例7: multipartHandler
func multipartHandler(req *web.Request) {
files, err := web.ParseMultipartForm(req, -1)
if err != nil {
req.Error(web.StatusBadRequest, err)
return
}
w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8")
if err := templates.ExecuteTemplate(w, "home.html", map[string]interface{}{"req": req, "files": files}); err != nil {
log.Print(err)
}
}
示例8: saveHandler
func saveHandler(req *web.Request) {
body := req.Param.Get("body")
title := req.URLParam["title"]
p := &page{Title: title, Body: []byte(body)}
err := p.save()
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
req.Redirect("/view/"+title, false)
}
示例9: serveProfile
func serveProfile(req *web.Request) {
sec, _ := strconv.ParseInt(req.Param.Get("seconds"), 10, 64)
if sec == 0 {
sec = 30
}
if err := pprof.StartCPUProfile(&lazyResponder{req, nil}); err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
time.Sleep(time.Duration(sec) * time.Second)
pprof.StopCPUProfile()
}
示例10: serveProfile
func serveProfile(req *web.Request) {
sec, _ := strconv.Atoi64(req.Param.Get("seconds"))
if sec == 0 {
sec = 30
}
if err := pprof.StartCPUProfile(&lazyResponder{req, nil}); err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
time.Sleep(sec * 1e9)
pprof.StopCPUProfile()
}
示例11: ServeWeb
// ServeWeb serves profile data for the pprof tool.
func ServeWeb(req *web.Request) {
switch {
case strings.HasSuffix(req.URL.Path, "/pprof/cmdline"):
io.WriteString(respondText(req), strings.Join(os.Args, "\x00"))
case strings.HasSuffix(req.URL.Path, "/pprof/profile"):
serveProfile(req)
case strings.HasSuffix(req.URL.Path, "/pprof/heap"):
pprof.WriteHeapProfile(respondText(req))
case strings.HasSuffix(req.URL.Path, "/pprof/symbol"):
serveSymbol(req)
default:
req.Error(web.StatusNotFound, nil)
}
}
示例12: homeHandler
// home handles requests to the home page.
func homeHandler(req *web.Request) {
token, err := accessToken(req)
if err != nil {
loggedOutHandler(req)
return
}
feed, err := getJSON("https://graph.facebook.com/me/home", web.NewValues("access_token", token))
if err != nil {
req.Error(web.StatusInternalServerError, err,
web.HeaderSetCookie, web.NewCookie("fbtok", "").Delete().String())
return
}
homeTemplate.respond(req, web.StatusOK, feed)
}
示例13: handleSign
func handleSign(r *web.Request) {
c := gae.Context(r)
g := &Greeting{
Content: r.Param.Get("content"),
Date: datastore.SecondsToTime(time.Seconds()),
}
if u := user.Current(c); u != nil {
g.Author = u.String()
}
if _, err := datastore.Put(c, datastore.NewIncompleteKey("Greeting"), g); err != nil {
r.Error(web.StatusInternalServerError, err)
return
}
r.Redirect("/", false)
}
示例14: handleMainPage
func handleMainPage(r *web.Request) {
c := gae.Context(r)
q := datastore.NewQuery("Greeting").Order("-Date").Limit(10)
var gg []*Greeting
_, err := q.GetAll(c, &gg)
if err != nil {
r.Error(web.StatusInternalServerError, err)
return
}
w := r.Respond(200, "Content-Type", "text/html")
if err := mainPage.Execute(w, map[string]interface{}{
"xsrf": r.Param.Get("xsrf"),
"gg": gg}); err != nil {
c.Logf("%v", err)
}
}
示例15: ServeWeb
func (ph *pageHandler) ServeWeb(req *web.Request) {
// Render page.
fmt.Println(req.URL.Path)
post, found := ph.context.Db.GetPage(req.URL.Path)
if !found {
req.Error(web.StatusNotFound, os.NewError("Not Found."))
return
}
local_context := *ph.context
local_context.Title = post.Title
local_context.Path = post.CanonicalBlogUrl.String() + post.CanonicalPath
var content bytes.Buffer
renderPost(&content, &local_context, post, post.CommentOnPage)
// Render page.
templates["main"].Execute(
req.Respond(web.StatusOK, web.HeaderContentType, "text/html"),
makeTemplateParams(&local_context, content.Bytes()))
}