Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BodyAsJson ¶ added in v0.1.1
BodyAsJson reads the entire body of an HTTP response and unmarshals it into the provided jsonBody. It consumes the response body, so the caller should not attempt to read from it again. The jsonBody parameter should be a pointer to a struct or a slice where JSON data will be unmarshaled.
Types ¶
type GracefulCancelFunc ¶ added in v0.1.0
GracefulCancelFunc defines a user-provided function that is called during shutdown for custom cleanup or cancellation logic. It receives a context and returns an error if the cancellation fails.
type GracefulServer ¶ added in v0.0.3
type GracefulServer struct {
Name string
*http.Server
context.Context
logger.Logger
SessionEngine session.Engine
ShutdownTimeout float64
CancelFunc GracefulCancelFunc
// contains filtered or unexported fields
}
GracefulServer combines an HTTP server with a context for graceful shutdown handling.
func NewGracefulServer ¶ added in v0.0.6
func NewGracefulServer(s *http.Server, name string) *GracefulServer
NewGracefulServer creates a new GracefulServer wrapping the given http.Server.
func (*GracefulServer) Run ¶ added in v0.0.3
func (s *GracefulServer) Run(sig ...os.Signal)
Run starts the HTTP server in a goroutine and listens for termination signals to gracefully shut down. It takes optional signals to listen for; if none are provided, it uses default signals.
func (*GracefulServer) TriggerShutdown ¶ added in v0.1.0
func (s *GracefulServer) TriggerShutdown() error
TriggerShutdown programmatically requests a graceful shutdown of the server. Returns an error if the shutdown cancel function is not available (e.g., Run has not been called).
func (*GracefulServer) WithCancelFunc ¶ added in v0.1.0
func (s *GracefulServer) WithCancelFunc(cancelFunc GracefulCancelFunc) *GracefulServer
WithCancelFunc sets a custom cancellation function to be called before shutdown. Returns the server for method chaining.
func (*GracefulServer) WithShutdownTimeout ¶ added in v0.1.0
func (s *GracefulServer) WithShutdownTimeout(timeout float64) *GracefulServer
WithShutdownTimeout sets the shutdown timeout (in seconds) for the server. Returns the server for method chaining.
type WrappedWriter ¶ added in v0.0.2
type WrappedWriter struct {
http.ResponseWriter
StatusCode int
}
WrappedWriter wraps an http.ResponseWriter to capture the status code of the response.
func (*WrappedWriter) WriteHeader ¶ added in v0.0.2
func (w *WrappedWriter) WriteHeader(c int)
WriteHeader records the status code and then calls the underlying WriteHeader method. This allows tracking of the response status without altering how the original ResponseWriter behaves.