本文整理匯總了Golang中github.com/bitly/nsq/util.ReqParams類的典型用法代碼示例。如果您正苦於以下問題:Golang ReqParams類的具體用法?Golang ReqParams怎麽用?Golang ReqParams使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ReqParams類的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
}