This commit is contained in:
Jake Keeys
2020-01-26 12:35:46 +00:00
commit f5de88e5bb
9 changed files with 764 additions and 0 deletions

46
internal/rest/server.go Normal file
View File

@@ -0,0 +1,46 @@
package rest
import (
"context"
"github.com/gorilla/handlers"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"net/http"
"os"
)
type Server struct {
httpSrv *http.Server
}
func New(bind string) *Server {
var s Server
r := http.NewServeMux()
r.Handle("/prometheus", promhttp.Handler())
server := http.Server{
Addr: bind,
Handler: handlers.LoggingHandler(os.Stdout, r),
}
s.httpSrv = &server
return &s
}
func (s Server) Start() {
go func() {
err := s.httpSrv.ListenAndServe()
if err != nil {
logrus.Panic(err)
}
}()
}
func (s Server) Stop() {
err := s.httpSrv.Shutdown(context.Background())
if err != nil {
logrus.Warn(err)
}
}