func (s *httpServer) indexHandler(w http.ResponseWriter, req *http.Request) { reqParams, err := http_api.NewReqParams(req) if err != nil { s.ctx.nsqadmin.logf("ERROR: failed to parse request params - %s", err) http.Error(w, "INVALID_REQUEST", 500) return } var topics []string if len(s.ctx.nsqadmin.opts.NSQLookupdHTTPAddresses) != 0 { topics, _ = lookupd.GetLookupdTopics(s.ctx.nsqadmin.opts.NSQLookupdHTTPAddresses) } else { topics, _ = lookupd.GetNSQDTopics(s.ctx.nsqadmin.opts.NSQDHTTPAddresses) } p := struct { Title string GraphOptions *GraphOptions Topics Topics Version string }{ Title: "NSQ", GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx), Topics: TopicsFromStrings(topics), Version: version.Binary, } err = templates.T.ExecuteTemplate(w, "index.html", p) if err != nil { s.ctx.nsqadmin.logf("Template Error %s", err) http.Error(w, "Template Error", 500) } }
func (s *httpServer) indexHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params) (interface{}, error) { reqParams, err := http_api.NewReqParams(req) if err != nil { return nil, http_api.Err{400, "INVALID_REQUEST"} } var topics []string if len(s.ctx.nsqadmin.opts.NSQLookupdHTTPAddresses) != 0 { topics, _ = lookupd.GetLookupdTopics(s.ctx.nsqadmin.opts.NSQLookupdHTTPAddresses) } else { topics, _ = lookupd.GetNSQDTopics(s.ctx.nsqadmin.opts.NSQDHTTPAddresses) } p := struct { Title string GraphOptions *GraphOptions Topics Topics Version string }{ Title: "NSQ", GraphOptions: NewGraphOptions(w, req, reqParams, s.ctx), Topics: TopicsFromStrings(topics), Version: version.Binary, } err = templates.T.ExecuteTemplate(w, "index.html", p) if err != nil { s.ctx.nsqadmin.logf("ERROR: executing template - %s", err) return nil, http_api.Err{500, "INTERNAL_ERROR"} } return nil, nil }