本文整理匯總了Golang中github.com/garyburd/twister/web.Request類的典型用法代碼示例。如果您正苦於以下問題:Golang Request類的具體用法?Golang Request怎麽用?Golang Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Request類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: renameTag
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)
}
示例2: mpPostHandler
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,
},
})
}
示例3: migrate
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")
}
示例4: mpGetHandler
func mpGetHandler(req *web.Request) {
mpTempl.Execute(
req.Respond(web.StatusOK, web.HeaderContentType, "text/html"),
map[string]interface{}{
"xsrf": req.Param.Get(web.XSRFParamName),
})
}
示例5: 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())
}
}
}
}
示例6: loginHandler
// 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)
}
示例7: 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."))
}
}
示例8: displayArchive
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))
}
示例9: createOrderHandler
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")
}
示例10: createCustomerHandler
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)
}
示例11: createEventHandler
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)
}
示例12: 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)
}
}
示例13: ServeHTTP
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)
}
}
示例14: 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)
}
示例15: createEntry
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"}))
}