Skip to content

Commit

Permalink
maj:misc: some options tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
burgesQ committed Jul 7, 2023
1 parent df6d8d8 commit 0c9cc23
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func InitServer(opts ...Option) (*Server, error) {
func WithHTTP2() Option {
return func(s *Server) {
s.meta.http2 = true
s.log.Debugf("\t-- logger loaded")
s.log.Debugf("\t-- http2 enabled")
}
}

Expand All @@ -129,7 +129,7 @@ func WithCtrlC() Option {
// when it's started.
func CheckIsUp() Option {
return func(s *Server) {
s.enableCheckIsUp()
s.EnableCheckIsUp()
s.log.Debugf("\t-- check is up support enabled")
}
}
Expand Down
9 changes: 7 additions & 2 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type (
// If a prefix is setup, the path will be prefixed.
Path string `json:"path"`

// NAme is used in message.
// Name is used in message.
Name string `json:"name"`
}

Expand Down Expand Up @@ -268,12 +268,17 @@ func (s *Server) GetRouter() *router.Router {
}
}

// TODO: register user group wise custom Handlers
// TODO: register group wise / route wise custom Handlers
// if route.handlers != nil {
// for _, h := range s.meta.handlers {
// handler = h(handleHandlerError(handler))
// }
// }
// if group.handlers != nil {
// for _, h := range s.meta.handlers {
// handler = h(handleHandlerError(handler))
// }
// }

if len(prefix) == 0 {
r.Handle(route.Verbe, route.Path, s.CustomHandler(handler))
Expand Down
29 changes: 25 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,34 @@ func (s *Server) StartTLS(addr string, cfg tls.IConfig) {
}

server := s.internalInit(addr)

if s.meta.http2 {
s.log.Infof("loading http2 support")
fasthttp2.ConfigureServer(server, fasthttp2.ServerConfig{Debug: true})
}

so2 := sOr2(s.meta.http2)

s.launcher.Start(func() {
s.log.Debugf("https server %s: starting", addr)
defer s.log.Infof("https server %s: done", addr)
s.log.Debugf("%s server %s: starting", so2, addr)
defer s.log.Infof("%s server %s: done", so2, addr)

go s.pollPingEndpoint(addr)

if e := server.Serve(listner); e != nil {
s.log.Errorf("https server %s (%T): %s", addr, e, e)
s.log.Errorf("%s server %s (%T): %s", so2, addr, e, e)
}
})
}

func sOr2(http2 bool) string {
if http2 {
return "http2"
}

return "https"
}

// ShutdownAndWait call for Shutdown and wait for all server to terminate.
func (s *Server) ShutdownAndWait() error {
defer s.WaitForStop()
Expand Down Expand Up @@ -328,12 +340,21 @@ func (s *Server) enableCORS() *Server {
// enableCheckIsUp add an /ping endpoint.
// If used, once a server is started, the user can check weather the server is
// up or not by reading the isReady channel vie the IsReady() method.
func (s *Server) enableCheckIsUp() *Server {
func (s *Server) EnableCheckIsUp() *Server {
s.meta.checkIsUp = true

return s
}

// DisableHTTP2 allow to disable HTTP2 on the fly.
// It usage isn't recommanded.
// For testing purpore only.
func (s *Server) DisableHTTP2() *Server {
s.meta.http2 = false

return s
}

// EnableCtrlC let the server handle the SIGINT interuption.
// To add worker to the interuption pool, please use the `GetLauncher` method.
func (s *Server) enableCtrlC() *Server {
Expand Down

0 comments on commit 0c9cc23

Please sign in to comment.