telegraf/internal/webserver/webserver.go

36 lines
622 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-25 19:12:12 +00:00
router *mux.Router
2016-05-25 17:38:25 +00:00
}
func NewWebserver() *Webserver {
2016-05-25 19:12:12 +00:00
return &Webserver{router: mux.NewRouter()}
2016-05-25 17:38:25 +00:00
}
func (wb *Webserver) Router() *mux.Router {
return wb.router
}
func (wb *Webserver) Listen() {
err := http.ListenAndServe(fmt.Sprintf("%s", wb.ServiceAddress), wb.router)
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
}