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
|
|
|
}
|
|
|
|
|
2016-05-27 08:17:11 +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
|
|
|
|
}
|