mirror of
https://github.com/kubevela/kubevela.git
synced 2026-03-05 19:22:03 +00:00
* Implement API `api/envs/default/apps/ implement API `api/envs/default/apps/ and refactor code * address comments from @wonderflow and @ryan * fix code rebase issue * Implement env APIs implemented APIs for env and make api-test and e2e-setup * fix ci issues * address comments
40 lines
822 B
Go
40 lines
822 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/cloud-native-application/rudrx/pkg/server/util"
|
|
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
)
|
|
|
|
type ApiServer struct {
|
|
server *http.Server
|
|
}
|
|
|
|
func (s *ApiServer) Launch(kubeClient client.Client) {
|
|
s.server = &http.Server{
|
|
Addr: util.Port,
|
|
Handler: setupRoute(kubeClient),
|
|
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)
|
|
}
|