mirror of
https://github.com/gl-inet/glkvm-cloud.git
synced 2026-09-16 15:45:16 +00:00
a5bce3b289
Complete the initial framework for resource-based permission management, providing the foundation for role-based access control and future permission extensions. Signed-off-by: GL.iNet-Yongping.Xie <yongping.xie@gl-inet.com>
43 lines
893 B
Go
Executable File
43 lines
893 B
Go
Executable File
package app
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type Server struct {
|
|
httpServer *http.Server
|
|
}
|
|
|
|
func NewServer(addr string, handler http.Handler) *Server {
|
|
return &Server{
|
|
httpServer: &http.Server{
|
|
Addr: addr,
|
|
Handler: handler,
|
|
ReadHeaderTimeout: 10 * time.Second,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (s *Server) Run(ctx context.Context) error {
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
errCh <- s.httpServer.ListenAndServe()
|
|
}()
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
_ = s.httpServer.Shutdown(shutdownCtx)
|
|
return nil
|
|
case err := <-errCh:
|
|
return err
|
|
}
|
|
}
|
|
|
|
func (s *Server) Shutdown(ctx context.Context) error {
|
|
return s.httpServer.Shutdown(ctx)
|
|
}
|