本文整理匯總了Golang中web.Context.SetHeader方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.SetHeader方法的具體用法?Golang Context.SetHeader怎麽用?Golang Context.SetHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類web.Context
的用法示例。
在下文中一共展示了Context.SetHeader方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getStyle
func getStyle(context *web.Context) {
b, err := ioutil.ReadFile("style.css")
context.SetHeader("Content-Type", "text/css", true)
if err != nil {
context.WriteString(err.String())
}
context.Write(b)
}
示例2: info
// function to display the info about a KurzUrl given by it's Key
func info(ctx *web.Context, short string) {
if strings.HasSuffix(short, "+") {
short = strings.Replace(short, "+", "", 1)
}
kurl, err := load(short)
if err == nil {
ctx.SetHeader("Content-Type", "application/json", true)
ctx.Write(kurl.Json())
ctx.WriteString("\n")
} else {
ctx.Redirect(http.StatusNotFound, ROLL)
}
}
示例3: latest
//Returns a json array with information about the last shortened urls. If data
// is a valid integer, that's the amount of data it will return, otherwise
// a maximum of 10 entries will be returned.
func latest(ctx *web.Context, data string) {
howmany, err := strconv.Atoi64(data)
if err != nil {
howmany = 10
}
c, _ := redis.Get(COUNTER)
last := c.Int64()
upTo := (last - howmany)
ctx.SetHeader("Content-Type", "application/json", true)
ctx.WriteString("{ \"urls\" : [")
for i := last; i > upTo && i > 0; i -= 1 {
kurl, err := load(Encode(i))
if err == nil {
ctx.Write(kurl.Json())
if i != upTo+1 {
ctx.WriteString(",")
}
}
}
ctx.WriteString("] }")
ctx.WriteString("\n")
}
示例4: get_rss
func get_rss(ctx *web.Context) {
log.Printf("get_rss\n")
ctx.SetHeader("Content-Type", "application/rss+xml", false)
t := rss_template
m := map[string]interface{}{"title": *title, "url": *url}
if entries, err := LoadRange("", *max_entries); err == nil {
type RSSEntry struct {
Entry
Guid string
RssDate string
}
rss_entries := make([]RSSEntry, len(entries))
for i, _ := range entries {
re := RSSEntry{entries[i], fmt.Sprintf("%s/%s", *url, entries[i].Id), nctime_to_rsstime(entries[i].Date)}
rss_entries[i] = re
}
m["entries"] = rss_entries
m["most_recent_date"] = nctime_to_rsstime(entries[0].Date)
s := mustache.Render(t, m)
ctx.WriteString(s)
} else {
ctx.WriteString(page(fmt.Sprintf("<p>Error generating RSS: %s</p>", err)))
}
}
示例5: prepareResponse
func (bs *BlockServer) prepareResponse(c *web.Context) {
c.ContentType("json")
c.SetHeader("Modata-NodeID", HexNodeID(bs.contact.ID), true)
c.SetHeader("Modata-Address", bs.contact.Addr, true)
c.SetHeader("Modata-Port", fmt.Sprintf("%v", bs.contact.Port), true)
}
示例6: get_css
func get_css(ctx *web.Context, path string) {
log.Printf("get_css\n")
ctx.SetHeader("Content-Type", "text/css", false)
ctx.WriteString(css_str)
}