52 lines
1018 B
Go
52 lines
1018 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
func (s *Server) Run(ctx context.Context) error {
|
|
s.ErrChan = make(chan error)
|
|
defer close(s.ErrChan)
|
|
|
|
tasks := make([]serverTask, 0)
|
|
var mux *http.ServeMux
|
|
if s.HttpListener != nil || s.HttpsListener != nil {
|
|
mux = http.NewServeMux()
|
|
}
|
|
|
|
if s.HttpListener != nil {
|
|
tasks = append(tasks, func() error {
|
|
return s.RunHttp(mux)
|
|
})
|
|
}
|
|
if s.HttpsListener != nil {
|
|
tasks = append(tasks, func() error {
|
|
return s.RunHttps(mux)
|
|
})
|
|
}
|
|
if s.GrpcListener != nil {
|
|
tasks = append(tasks, func() error {
|
|
return s.RunGrpc()
|
|
})
|
|
}
|
|
|
|
return s.execTasks(ctx, tasks)
|
|
}
|
|
|
|
func (s *Server) RunHttp(mux http.Handler) error {
|
|
fmt.Println("Running HTTP server")
|
|
return http.Serve(s.HttpsListener, mux)
|
|
}
|
|
|
|
func (s *Server) RunHttps(mux http.Handler) error {
|
|
fmt.Println("Running HTTPS server")
|
|
return http.ServeTLS(s.HttpsListener, mux, s.Cfg.TlsCfg.Cert, s.Cfg.TlsCfg.Key)
|
|
}
|
|
|
|
func (s *Server) RunGrpc() error {
|
|
panic("Not implemented")
|
|
return nil
|
|
}
|