Documentation
¶
Index ¶
- type ErrorHandler
- type Group
- type Server
- func (s *Server) ErrorHandler(h ErrorHandler)
- func (s *Server) Group(prefix string, middleware ...ctx.Handler) *Group
- func (s *Server) IsReady() bool
- func (s *Server) ListenAndShutdown(onShutdown ...func()) error
- func (s *Server) ListenAndShutdownTLS(certFile, keyFile string, onShutdown ...func()) error
- func (s *Server) Route(method web.Method, path string, h ctx.Handler)
- func (s *Server) SetTLSConfig(cfg *tls.Config)
- func (s *Server) Start() error
- func (s *Server) StartTLS(certFile, keyFile string) error
- func (s *Server) Static(prefix, dir string)
- func (s *Server) StaticFS(prefix string, fsys fs.FS)
- func (s *Server) Stop() error
- func (s *Server) Use(mw ...ctx.Handler)
- func (s *Server) WaitUntilReady()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorHandler ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group represents a route group with a shared path prefix and middleware.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) ErrorHandler ¶
func (s *Server) ErrorHandler(h ErrorHandler)
func (*Server) Group ¶
Group creates a new route group with the given path prefix and optional middleware. The group middleware runs after server-level middleware and before the route handler.
api := srv.Group("/api/v1", authMiddleware)
api.Route(web.MethodGet, "/users", listUsers) // handles GET /api/v1/users
api.Route(web.MethodPost, "/users", createUser) // handles POST /api/v1/users
func (*Server) ListenAndShutdown ¶
ListenAndShutdown starts the server and blocks until a SIGINT or SIGTERM signal is received, then performs a graceful shutdown. The optional onShutdown callbacks are invoked after the HTTP server stops (use them to close databases, flush logs, etc.). Returns nil when the server shuts down cleanly.
func (*Server) ListenAndShutdownTLS ¶
ListenAndShutdownTLS is like ListenAndShutdown but starts the server with TLS.
func (*Server) Route ¶
Route registers a route handler for the given method and path. Path params can be defined as :param or {param}.
func (*Server) SetTLSConfig ¶
SetTLSConfig sets a custom TLS configuration on the server. Call this before StartTLS or ListenAndShutdownTLS for advanced scenarios like mutual TLS or custom cipher suites.
func (*Server) StartTLS ¶
StartTLS starts the server with TLS using the provided certificate and key files.
func (*Server) Static ¶
Static serves files from the given directory under the specified URL prefix. The prefix must start and end with a slash (e.g., "/static/").
srv.Static("/static/", "./public")
func (*Server) StaticFS ¶
StaticFS serves files from the given fs.FS under the specified URL prefix. This is useful for embedding static files with go:embed.
//go:embed static
var staticFiles embed.FS
srv.StaticFS("/static/", staticFiles)
func (*Server) WaitUntilReady ¶
func (s *Server) WaitUntilReady()