http

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2021 License: MIT Imports: 10 Imported by: 2

Documentation

Overview

Package http implements helpers for HTTP requests.

Index

Constants

View Source
const JSONContentType = "application/json"

JSONContentType represents MIME type for JSON content.

Variables

View Source
var DefaultHealthPath = "/health"

DefaultHealthPath is the default HTTP path for checking health.

Functions

func JSON

func JSON(w http.ResponseWriter, code int, v interface{}) error

JSON encodes json content to the ResponseWriter.

func NewHealthHandler

func NewHealthHandler(v ...Health) http.HandlerFunc

NewHealthHandler returns a handler for application health checking.

func RealIP

func RealIP(r *http.Request) string

RealIP resolves the real client IP address from the request.

Types

type Health

type Health interface {
	IsHealthy() error
}

Health represents an object that can check its health.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a convenience wrapper around the standard library http server.

func NewServer

func NewServer(ctx context.Context, addr string, h http.Handler, opts ...SrvOptFunc) *Server

NewServer returns a server.

func (*Server) Close

func (s *Server) Close() error

Close closes the server.

func (*Server) Serve

func (s *Server) Serve(errFn func(error))

Serve starts the server in a in-blocking way.

func (*Server) Shutdown

func (s *Server) Shutdown(timeout time.Duration) error

Shutdown attempts to close all server connections.

type SrvOptFunc

type SrvOptFunc func(*http.Server)

SrvOptFunc represents a server option function.

func WithH2C added in v2.2.0

func WithH2C() SrvOptFunc

WithH2C allows the server to handle h2c connections.

func WithTLSConfig

func WithTLSConfig(cfg *tls.Config) SrvOptFunc

WithTLSConfig sets the serve tls config.

Directories

Path Synopsis
Package middleware implements reusable HTTP middleware.
Package middleware implements reusable HTTP middleware.

Jump to

Keyboard shortcuts

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