pidgin/carrier

ca0c732f744b
Copy in ca-certs from the build container to the resulting container
package server
import (
"net/http"
log "github.com/sirupsen/logrus"
"bitbucket.org/pidgin/carrier/uptimerobot"
)
type Server struct {
server *http.Server
errChan chan error
}
func healthzHandler(w http.ResponseWriter, r *http.Request) {
status := http.StatusMethodNotAllowed
if r.Method == http.MethodGet {
status = http.StatusOK
}
w.WriteHeader(status)
}
func httpLogger(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Infof("%s %s %s\n", r.RemoteAddr, r.Method, r.URL)
handler.ServeHTTP(w, r)
})
}
func NewServer(addr string, errChan chan error) *Server {
mux := http.NewServeMux()
mux.HandleFunc("/healthz", healthzHandler)
mux.HandleFunc("/uptime-robot", uptimerobot.Handler)
return &Server{
errChan: errChan,
server: &http.Server{
Addr: addr,
Handler: httpLogger(mux),
},
}
}
func (s *Server) Start() {
log.Infof("http server started")
s.errChan <- s.server.ListenAndServe()
}
func (s *Server) Stop() {
s.server.Close()
}