func renameTag(req *web.Request) { // oldTag := req.Param.Get("oldTag") newTag := req.Param.Get("newTag") // updateTag(oldTag, newTag) url := fmt.Sprintf("/tag/%s", url.QueryEscape(newTag)) req.Redirect(url, false) }
func mpPostHandler(req *web.Request) { parts, err := web.ParseMultipartForm(req, -1) var ( filename, contentType string contentParam map[string]string size int ) if len(parts) > 0 { filename = parts[0].Filename contentType = parts[0].ContentType contentParam = parts[0].ContentParam size = len(parts[0].Data) } mpTempl.Execute( req.Respond(web.StatusOK, web.HeaderContentType, "text/html"), map[string]interface{}{ "xsrf": req.Param.Get(web.XSRFParamName), "result": map[string]interface{}{ "err": err, "hello": req.Param.Get("hello"), "foo": req.Param.Get("foo"), "filename": filename, "contentType": contentType, "contentParam": contentParam, "size": size, }, }) }
func migrate(req *web.Request) { err := db.Query("select id, message, date from entries") if err != nil { panic(err) } result, err := db.StoreResult() if err != nil { panic(err) } itemIndex := make(map[string]Item, result.RowCount()) for _, entry_row := range result.FetchRows() { id := string([]uint8(entry_row[0].([]uint8))) message := string([]uint8(entry_row[1].([]uint8))) when := entry_row[2].(int64) itemIndex[id] = Item{message, "", make([]string, 0), bson.MongoTimestamp(when)} } db.FreeResult() for id, item := range itemIndex { tags := getTags(id) // log.Println(id, tags) // item.Tags = tags // itemIndex[id] = item createItem(item.Message, "", tags, int64(item.When)) } log.Println(itemIndex) w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") io.WriteString(w, "OK") }
func mpGetHandler(req *web.Request) { mpTempl.Execute( req.Respond(web.StatusOK, web.HeaderContentType, "text/html"), map[string]interface{}{ "xsrf": req.Param.Get(web.XSRFParamName), }) }
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()) } } } }
// loginHandler redirects to Facebook OAuth2 authorization page. func loginHandler(req *web.Request) { m := web.NewValues( "client_id", appID, // defined in settings.go "scope", "read_stream", "redirect_uri", req.URL.Scheme+"://"+req.URL.Host+"/callback") req.Redirect("https://graph.facebook.com/oauth/authorize?"+m.FormEncodedString(), false) }
// 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.")) } }
func displayArchive(req *web.Request) { entries := getEntries() entryGroups := flattenEntryGroups(groupEntries(entries)) w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") params := make(map[string]interface{}) params["entry_groups"] = entryGroups io.WriteString(w, RenderFile("templates/archive.html", params)) }
func createOrderHandler(req *web.Request) { name := req.Param.Get("name") companyId := req.Param.Get("company") id := NewUUID() storeOrder(id.String(), name, companyId) w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") io.WriteString(w, "ok") }
func createCustomerHandler(req *web.Request) { orderId := req.Param.Get("order") name := req.Param.Get("name") email := req.Param.Get("email") id := NewUUID() storeCustomer(id.String(), name, email) req.Redirect("/order/?id="+orderId, false) }
func createEventHandler(req *web.Request) { orderId := req.Param.Get("order") name := req.Param.Get("name") value := req.Param.Get("value") id := NewUUID() storeEvent(id.String(), orderId, name, value) req.Redirect("/order/?id="+orderId, false) }
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) } }
func ServeHTTP(req *web.Request) { s := req.Param.GetDef("txt", "") ni, _ := strconv.Atoi(req.Param.GetDef("num", "")) wr := req.Respond(web.StatusOK) for i := 0; i < ni; i++ { fmt.Fprintf(wr, "%d: %s\n", i, s) } }
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) }
func createEntry(req *web.Request) { message := req.Param.Get("message") extra := req.Param.Get("extra") tags := splitTags(extra) when := getTime(tags) createItem(message, extra, tags, when) w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") io.WriteString(w, RenderFile("templates/index.html", map[string]string{"c": "world"})) }
func createOrderFormHandler(req *web.Request) { w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") companies := listCompanies() params := make(map[string]interface{}) params["Companies"] = companies io.WriteString(w, RenderFile("templates/order-create.html", params)) }
func coreErrorHandler(req *web.Request, status int, message string) { coreTempl.Execute(map[string]interface{}{ "req": req, "status": status, "message": message, "xsrf": req.Param.GetDef(web.XSRFParamName, ""), }, req.Respond(status, web.HeaderContentType, "text/html")) }
func coreHandler(req *web.Request) { coreTempl.Execute(map[string]interface{}{ "req": req, "status": web.StatusOK, "message": "ok", "xsrf": req.Param.GetDef(web.XSRFParamName, ""), }, req.Respond(web.StatusOK, web.HeaderContentType, "text/html")) }
func createEntry(req *web.Request) { message := req.Param.Get("message") extra := req.Param.Get("extra") tags := splitTags(extra) id := NewUUID() storeEntry(id, message, tags) w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") io.WriteString(w, RenderFile("templates/index.html", map[string]string{"c": "world"})) }
func viewHandler(req *web.Request) { title := req.URLParam["title"] p, err := loadPage(title) if err != nil { req.Redirect("/edit/"+title, false) return } renderTemplate(req, "view", p) }
func displayArchive(req *web.Request) { result := getItems(nil, 250) groupedItems := groupItems(result) flatItemGroups := flattenItemGroups(groupedItems) w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") params := make(map[string]interface{}) params["entry_groups"] = flatItemGroups io.WriteString(w, RenderFile("templates/archive.html", params)) }
// 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)) }
func createCompanyHandler(req *web.Request) { name := req.Param.Get("name") address := req.Param.Get("address") phone := req.Param.Get("phone") url := req.Param.Get("url") id := NewUUID() storeCompany(id.String(), name, address, phone, url) w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") io.WriteString(w, "ok") }
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) }
func renderTemplate(req *web.Request, tmpl string, p *page) { err := templates[tmpl].Execute( req.Respond(web.StatusOK), map[string]interface{}{ "page": p, "xsrf": req.Param.Get("xsrf"), }) if err != nil { log.Println("error rendering", tmpl, err) } }
func renderRssTemplate(req *web.Request, status int, tmpl string, results []*NewsItem) { fmt.Println(tmpl, "rendering") err := templates[tmpl].Execute( req.Respond(status, web.HeaderContentType, "application/rss+xml"), map[string]interface{}{ "results": results, }) if err != nil { log.Println("error rendering", tmpl, err) } }
func renderTemplate(req *web.Request, tmpl string, p *page) { err := templates[tmpl].Execute( req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset='utf-8'"), map[string]interface{}{ "page": p, "xsrf": req.Param.Get("xsrf"), }) if err != nil { log.Println("error rendering", tmpl, err) } }
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) } }
func displayTag(req *web.Request) { w := req.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=\"utf-8\"") params := make(map[string]interface{}) if tag, ok := req.URLParam["tag"]; ok { result := getItems(bson.M{"tags": bson.M{"$in": []string{tag}}}, 1000) groupedItems := groupItems(result) params["tag"] = tag params["entry_groups"] = flattenItemGroups(groupedItems) } io.WriteString(w, RenderFile("templates/tag.html", params)) }
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() }