harness-drone/shared/server/server.go

37 lines
623 B
Go
Raw Normal View History

2015-09-30 01:21:17 +00:00
package server
import (
"net/http"
log "github.com/Sirupsen/logrus"
"github.com/drone/drone/shared/envconfig"
)
type Server struct {
Addr string
Cert string
Key string
}
func Load(env envconfig.Env) *Server {
return &Server{
Addr: env.String("SERVER_ADDR", ":8000"),
Cert: env.String("SERVER_CERT", ""),
Key: env.String("SERVER_KEY", ""),
}
}
func (s *Server) Run(handler http.Handler) {
log.Infof("starting server %s", s.Addr)
if len(s.Cert) != 0 {
log.Fatal(
http.ListenAndServeTLS(s.Addr, s.Cert, s.Key, handler),
)
} else {
log.Fatal(
http.ListenAndServe(s.Addr, handler),
)
}
}