address code review comments re. style/structure
This commit is contained in:
parent
5866acd48d
commit
6da73ded58
|
@ -61,13 +61,19 @@ func (t *HttpListener) Start(acc telegraf.Accumulator) error {
|
|||
t.acc = acc
|
||||
|
||||
var rawListener, err = net.Listen("tcp", t.ServiceAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.listener, err = stoppableListener.New(rawListener)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go t.httpListen()
|
||||
|
||||
log.Printf("Started HTTP listener service on %s\n", t.ServiceAddress)
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop cleans up all resources
|
||||
|
@ -85,7 +91,13 @@ func (t *HttpListener) Stop() {
|
|||
func (t *HttpListener) httpListen() error {
|
||||
|
||||
readTimeout, err := strconv.ParseInt(t.ReadTimeout, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
writeTimeout, err := strconv.ParseInt(t.WriteTimeout, 10, 32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var server = http.Server{
|
||||
Handler: t,
|
||||
|
@ -93,15 +105,18 @@ func (t *HttpListener) httpListen() error {
|
|||
WriteTimeout: time.Duration(writeTimeout) * time.Second,
|
||||
}
|
||||
|
||||
err = server.Serve(t.listener)
|
||||
|
||||
return err
|
||||
return server.Serve(t.listener)
|
||||
}
|
||||
|
||||
func (t *HttpListener) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
|
||||
if err == nil {
|
||||
if err != nil {
|
||||
log.Printf("Problem reading request: [%s], Error: %s\n", string(body), err)
|
||||
res.WriteHeader(http.StatusInternalServerError)
|
||||
res.Write([]byte("ERROR reading request"))
|
||||
}
|
||||
|
||||
var path = req.URL.Path[1:]
|
||||
|
||||
if path == "write" {
|
||||
|
@ -127,11 +142,6 @@ func (t *HttpListener) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
|||
res.WriteHeader(http.StatusNotFound)
|
||||
res.Write([]byte("Not Found"))
|
||||
}
|
||||
} else {
|
||||
log.Printf("Problem reading request: [%s], Error: %s\n", string(body), err)
|
||||
res.WriteHeader(http.StatusInternalServerError)
|
||||
res.Write([]byte("ERROR reading request"))
|
||||
}
|
||||
}
|
||||
|
||||
func (t *HttpListener) storeMetrics(metrics []telegraf.Metric) error {
|
||||
|
|
Loading…
Reference in New Issue