func (s *httpServer) statsHandler(w http.ResponseWriter, req *http.Request) { reqParams, err := util.NewReqParams(req) if err != nil { log.Printf("ERROR: failed to parse request params - %s", err) if acceptVersion(req) == 1 { util.V1ApiResponse(w, 400, "INVALID_REQUEST") } else { // this handler always returns 500 for backwards compatibility util.ApiResponse(w, 500, "INVALID_REQUEST", nil) } return } formatString, _ := reqParams.Get("format") jsonFormat := formatString == "json" stats := s.context.nsqd.GetStats() if !jsonFormat { s.doTextStats(stats, w) return } if acceptVersion(req) == 1 { util.V1ApiResponse(w, 200, struct { Version string `json:"version"` Topics []TopicStats `json:"topics"` }{util.BINARY_VERSION, stats}) } else { util.ApiResponse(w, 200, "OK", struct { Version string `json:"version"` Topics []TopicStats `json:"topics"` }{util.BINARY_VERSION, stats}) } }
func (s *httpServer) v1PauseChannelHandler(w http.ResponseWriter, req *http.Request) { if req.Method != "POST" { util.V1ApiResponse(w, 405, "INVALID_REQUEST") return } err := s.doPauseChannel(req) if err != nil { util.V1ApiResponse(w, err.(httpError).Code(), err) return } util.V1ApiResponse(w, 200, "OK") }
func (s *httpServer) v1CreateTopicHandler(w http.ResponseWriter, req *http.Request) { if req.Method != "POST" { util.V1ApiResponse(w, 405, "INVALID_REQUEST") return } _, _, err := s.getTopicFromQuery(req) if err != nil { util.V1ApiResponse(w, err.(httpError).Code(), err) return } util.V1ApiResponse(w, 200, "OK") }
func (s *httpServer) pauseChannelHandler(w http.ResponseWriter, req *http.Request) { err := s.doPauseChannel(req) if err != nil { if acceptVersion(req) == 1 { util.V1ApiResponse(w, err.(httpError).Code(), err) } else { // this handler always returns 500 for backwards compatibility util.ApiResponse(w, 500, err.Error(), nil) } return } if acceptVersion(req) == 1 { util.V1ApiResponse(w, 200, nil) } else { util.ApiResponse(w, 200, "OK", nil) } }
func (s *httpServer) createTopicHandler(w http.ResponseWriter, req *http.Request) { _, _, err := s.getTopicFromQuery(req) if err != nil { if acceptVersion(req) == 1 { util.V1ApiResponse(w, err.(httpError).Code(), err) } else { // this handler always returns 500 for backwards compatibility util.ApiResponse(w, 500, err.Error(), nil) } return } if acceptVersion(req) == 1 { util.V1ApiResponse(w, 200, nil) } else { util.ApiResponse(w, 200, "OK", nil) } }
func (s *httpServer) mpubHandler(w http.ResponseWriter, req *http.Request) { err := s.doMPUB(req) if err != nil { if acceptVersion(req) == 1 { util.V1ApiResponse(w, err.(httpError).Code(), err) } else { // this handler always returns 500 for backwards compatibility util.ApiResponse(w, 500, err.Error(), nil) } return } w.Header().Set("Content-Length", "2") io.WriteString(w, "OK") }