2024-11-13 21:10:13 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) Run(ctx context.Context) error {
|
2024-11-24 14:04:52 +00:00
|
|
|
s.ErrChan = make(chan error)
|
|
|
|
defer close(s.ErrChan)
|
|
|
|
|
|
|
|
tasks := make([]serverTask, 0)
|
2024-11-13 21:10:13 +00:00
|
|
|
var mux *http.ServeMux
|
|
|
|
if s.HttpListener != nil || s.HttpsListener != nil {
|
|
|
|
mux = http.NewServeMux()
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.HttpListener != nil {
|
2024-11-24 14:04:52 +00:00
|
|
|
tasks = append(tasks, func() error {
|
|
|
|
return s.RunHttp(mux)
|
2024-11-13 21:10:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
if s.HttpsListener != nil {
|
2024-11-24 14:04:52 +00:00
|
|
|
tasks = append(tasks, func() error {
|
|
|
|
return s.RunHttps(mux)
|
2024-11-13 21:10:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
if s.GrpcListener != nil {
|
2024-11-24 14:04:52 +00:00
|
|
|
tasks = append(tasks, func() error {
|
|
|
|
return s.RunGrpc()
|
2024-11-13 21:10:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-11-24 14:04:52 +00:00
|
|
|
return s.execTasks(ctx, tasks)
|
2024-11-13 21:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|