本文整理匯總了Golang中github.com/garyburd/twister/web.Request.Respond方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Respond方法的具體用法?Golang Request.Respond怎麽用?Golang Request.Respond使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/garyburd/twister/web.Request
的用法示例。
在下文中一共展示了Request.Respond方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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),
})
}
示例2: home
// home handles requests to the home page.
func home(req *web.Request) {
token, err := credentials(req, "tok")
if err != nil {
homeLoggedOut(req)
return
}
param := make(web.Values)
url := "http://api.twitter.com/1/statuses/home_timeline.json"
oauthClient.SignParam(token, "GET", url, param)
url = url + "?" + param.FormEncodedString()
resp, err := http.Get(url)
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
req.Error(web.StatusInternalServerError, os.NewError(fmt.Sprint("Status ", resp.StatusCode)))
return
}
var d interface{}
err = json.NewDecoder(resp.Body).Decode(&d)
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
homeTempl.Execute(req.Respond(web.StatusOK, web.HeaderContentType, web.ContentTypeHTML), d)
}
示例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: 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,
},
})
}
示例5: 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."))
}
}
示例6: 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)
}
示例7: 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)
}
}
示例8: 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")
}
示例9: 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))
}
示例10: 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"}))
}
示例11: coreHandler
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"))
}
示例12: createEntry
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"}))
}
示例13: coreErrorHandler
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"))
}
示例14: createOrderFormHandler
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))
}
示例15: displayArchive
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))
}