telegraf/internal/webserver/webserver.go

36 lines
622 B
Go

package webserver
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
type Webserver struct {
ServiceAddress string
router *mux.Router
}
func NewWebserver() *Webserver {
return &Webserver{router: mux.NewRouter()}
}
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
}