httputil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenRevoked = errors.New("token expired or revoked")

ErrTokenRevoked signifies a token revokation or expiration error

Functions

func Client

func Client(method, endpoint, userAgent string, headers map[string]string, params url.Values, response interface{}) error

Client provides a simple helper interface to make HTTP requests

func Error added in v0.0.5

func Error(message string, code int, err error) error

Error formats creates a HTTP error with code, user friendly (and safe) error message. If nil or empty: HTTP status code defaults to 500. Message defaults to the text of the status code.

func ErrorResponse

func ErrorResponse(rw http.ResponseWriter, r *http.Request, e error)

ErrorResponse renders an error page given an error. If the error is a http error from this package, a user friendly message is set, http status code, the ability to debug are also set.

func NewHTTPServer added in v0.2.0

func NewHTTPServer(opt *ServerOptions, h http.Handler) *http.Server

NewHTTPServer starts a http server given a set of options and a handler.

It is the caller's responsibility to Close() or Shutdown() the returned server.

func NewTLSServer added in v0.2.0

func NewTLSServer(opt *ServerOptions, httpHandler http.Handler, grpcHandler http.Handler) (*http.Server, error)

NewTLSServer creates a new TLS server given a set of options, handlers, and optionally a set of gRPC endpoints as well. It is the callers responsibility to close the resturned server.

func RedirectHandler added in v0.2.0

func RedirectHandler() http.Handler

func Shutdown added in v0.2.0

func Shutdown(srv *http.Server)

Shutdown attempts to shut down the server when a os interrupt or sigterm signal are received without interrupting any active connections. Shutdown works by first closing all open listeners, then closing all idle connections, and then waiting indefinitely for connections to return to idle and then shut down. If the provided context expires before the shutdown is complete, Shutdown returns the context's error, otherwise it returns any error returned from closing the Server's underlying Listener(s).

When Shutdown is called, Serve, ListenAndServe, and ListenAndServeTLS immediately return ErrServerClosed.

Types

type ServerOptions added in v0.2.0

type ServerOptions struct {
	// Addr specifies the host and port on which the server should serve
	// HTTPS requests. If empty, ":443" is used.
	Addr string

	// TLS certificates to use.
	Cert     string
	Key      string
	CertFile string
	KeyFile  string

	// Timeouts
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
}

ServerOptions contains the configurations settings for a http server.

Jump to

Keyboard shortcuts

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