mirror of
https://github.com/kubevela/kubevela.git
synced 2026-03-05 19:22:03 +00:00
37 lines
679 B
Go
37 lines
679 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
)
|
|
|
|
type ApiServer struct {
|
|
server *http.Server
|
|
}
|
|
|
|
func (s *ApiServer) Launch() {
|
|
s.server = &http.Server{
|
|
Addr: ":8080",
|
|
Handler: setupRoute(),
|
|
ReadTimeout: 5 * time.Second,
|
|
WriteTimeout: 10 * time.Second,
|
|
}
|
|
s.server.SetKeepAlivesEnabled(true)
|
|
|
|
go (func() error {
|
|
err := s.server.ListenAndServe()
|
|
if err != nil && err != http.ErrServerClosed {
|
|
ctrl.Log.Error(err, "failed to start the server")
|
|
}
|
|
return err
|
|
})()
|
|
}
|
|
|
|
func (s *ApiServer) Shutdown(ctx context.Context) error {
|
|
ctrl.Log.Info("sever shutting down")
|
|
return s.server.Shutdown(ctx)
|
|
}
|