mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-25 09:50:31 +00:00
36 lines
623 B
Go
36 lines
623 B
Go
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),
|
|
)
|
|
}
|
|
}
|