httpok

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 12 Imported by: 1

README

Candango HTTPok

Welcome to the world of httpok, your Go library for extending the capabilities of the standard net/http package!

Installation

To get httpok, you can use go get:

go get github.com/candango/httpok

Support

HttpOK is one of Candango Open Source Group initiatives. Available under the MIT License.

This site and all documentation are licensed under Creative Commons 3.0.

Copyright © 2024-2026 Flavio Garcia

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyAsJson added in v0.1.1

func BodyAsJson(res *http.Response, jsonBody any) error

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.

func BodyAsString added in v0.1.1

func BodyAsString(res *http.Response) (string, error)

BodyAsString reads the entire body of an HTTP response and returns it as a string. It consumes the response body, so the caller should not attempt to read from it again.

Types

type GracefulCancelFunc added in v0.1.0

type GracefulCancelFunc func(context.Context) error

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.

Directories

Path Synopsis
cmd
sess command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL