本文整理汇总了Golang中github.com/bitly/nsq/util.ReqParams.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang ReqParams.Get方法的具体用法?Golang ReqParams.Get怎么用?Golang ReqParams.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bitly/nsq/util.ReqParams
的用法示例。
在下文中一共展示了ReqParams.Get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewGraphOptions
func NewGraphOptions(rw http.ResponseWriter, req *http.Request, r *util.ReqParams) *GraphOptions {
selectedTimeString, err := r.Get("t")
if err != nil && selectedTimeString == "" {
// get from cookie
cookie, err := req.Cookie("t")
if err != nil {
selectedTimeString = "2h"
} else {
selectedTimeString = cookie.Value
}
} else {
// set cookie
host, _, _ := net.SplitHostPort(req.Host)
cookie := &http.Cookie{
Name: "t",
Value: selectedTimeString,
Path: "/",
Domain: host,
Expires: time.Now().Add(time.Duration(720) * time.Hour),
HttpOnly: true,
}
http.SetCookie(rw, cookie)
}
g, err := GraphIntervalForTimeframe(selectedTimeString, true)
if err != nil {
g, _ = GraphIntervalForTimeframe("2h", true)
}
base := *graphiteUrl
configured := base != ""
enabled := configured
if *proxyGraphite {
base = ""
}
if g.Timeframe == "off" {
enabled = false
}
o := &GraphOptions{
Configured: configured,
Enabled: enabled,
UseStatsdPrefix: *useStatsdPrefixes,
StatsdPrefix: *statsdPrefix,
GraphiteUrl: base,
AllGraphIntervals: DefaultGraphTimeframes(selectedTimeString),
GraphInterval: g,
}
return o
}
示例2: NewGraphOptions
func NewGraphOptions(rw http.ResponseWriter, req *http.Request,
r *util.ReqParams, context *Context) *GraphOptions {
selectedTimeString, err := r.Get("t")
if err != nil && selectedTimeString == "" {
// get from cookie
cookie, err := req.Cookie("t")
if err != nil {
selectedTimeString = "2h"
} else {
selectedTimeString = cookie.Value
}
} else {
// set cookie
host, _, _ := net.SplitHostPort(req.Host)
cookie := &http.Cookie{
Name: "t",
Value: selectedTimeString,
Path: "/",
Domain: host,
Expires: time.Now().Add(time.Duration(720) * time.Hour),
HttpOnly: true,
}
http.SetCookie(rw, cookie)
}
g, err := GraphIntervalForTimeframe(selectedTimeString, true)
if err != nil {
g, _ = GraphIntervalForTimeframe("2h", true)
}
base := context.nsqadmin.options.GraphiteURL
if context.nsqadmin.options.ProxyGraphite {
base = ""
}
o := &GraphOptions{
context: context,
Configured: context.nsqadmin.options.GraphiteURL != "",
Enabled: g.Timeframe != "off" && context.nsqadmin.options.GraphiteURL != "",
GraphiteUrl: base,
AllGraphIntervals: DefaultGraphTimeframes(selectedTimeString),
GraphInterval: g,
}
return o
}