telegraf/internal/webserver/webserver.go

32 lines
610 B
Go
Raw Normal View History

2016-05-25 17:38:25 +00:00
package webserver
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
type Webserver struct {
ServiceAddress string
2016-05-27 08:19:33 +00:00
Router *mux.Router
2016-05-25 17:38:25 +00:00
}
func NewWebserver(serviceAddress string) *Webserver {
return &Webserver{Router: mux.NewRouter(), ServiceAddress: serviceAddress}
2016-05-25 17:38:25 +00:00
}
func (wb *Webserver) Listen() {
2016-05-27 08:19:33 +00:00
err := http.ListenAndServe(fmt.Sprintf("%s", wb.ServiceAddress), wb.Router)
2016-05-25 17:38:25 +00:00
if err != nil {
log.Printf("Error starting server: %v", err)
}
}
func (wb *Webserver) Start() error {
go wb.Listen()
log.Printf("Started the webhook server on %s\n", wb.ServiceAddress)
return nil
}