httplib

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 13 Imported by: 0

README

httplib

Go HTTP library.

Dependencies (see go.mod):

Middleware dependencies:

  • chi for routing and middleware

package middleware

Provides a request logger middleware based on zerolog.

Documentation

Index

Constants

View Source
const (
	// ContentType content type HTTP header key
	ContentType = "Content-Type"

	// ContentTypeApplicationJSON JSON content type HTTP header value
	ContentTypeApplicationJSON = "application/json; charset=utf-8"

	// ContentTypeTextPlain text content type HTTP header value
	ContentTypeTextPlain = "text/plain; charset=utf-8"

	// PrettyParameter URL parameter for pretty printing JSON
	PrettyParameter = "pretty"
)

Variables

This section is empty.

Functions

func Decode

func Decode(w http.ResponseWriter, r *http.Request, v interface{}) error

Decode decodes HTTP request data.

func GetIntQueryParam added in v0.3.0

func GetIntQueryParam(r *http.Request, key string, defaultValue int) int

GetIntQueryParam returns a request URL query parameter as an int or a default value.

func GetQueryParam added in v0.3.1

func GetQueryParam(r *http.Request, key, defaultValue string) string

GetQueryParam returns a trimmed request URL query parameter or a default value.

func Handle

func Handle(h HandlerFunc) http.HandlerFunc

Handle converts a Handler into a standard http.HandlerFunc

func NewServer

func NewServer(host string, port uint16, handler http.Handler) *http.Server

NewServer returns a default HTTP server.

func NewSignalsChannel

func NewSignalsChannel() chan os.Signal

NewSignalsChannel creates a new channel for interrupt signals.

func Respond

func Respond(w http.ResponseWriter, r *http.Request, code int, i interface{}) error

Respond encodes HTTP response data.

func RespondJSON

func RespondJSON(w http.ResponseWriter, r *http.Request, code int, i interface{}) error

RespondJSON encodes HTTP response data as JSON. Indentation can be controlled by a url query parameter 'pretty'.

func RespondText

func RespondText(w http.ResponseWriter, r *http.Request, code int, s string) error

RespondText encodes HTTP response data as plain text.

func StartServer

func StartServer(s *http.Server, c chan os.Signal) error

StartServer start an HTTP server.

Types

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request) error

HandlerFunc is a http.HandlerFunc that returns an error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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