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 }
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 }