xhttp

package
Version: v0.0.0-...-9649366 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidParams is returned when input parameters are invalid
	ErrInvalidParams = errors.New("invalid request params")
)

Functions

func DurationToNanosBytes

func DurationToNanosBytes(r io.Reader) ([]byte, error)

DurationToNanosBytes transforms a json byte slice with Duration keys into Nanos

func DurationToNanosMap

func DurationToNanosMap(input map[string]interface{}) (map[string]interface{}, error)

DurationToNanosMap transforms keys with a Duration into Nanos

func Error

func Error(w http.ResponseWriter, err error, code int)

Error will serve an HTTP error

func IsInvalidParams

func IsInvalidParams(err error) bool

IsInvalidParams returns true if this is an invalid params error

func NanosToDurationBytes

func NanosToDurationBytes(r io.Reader) (map[string]interface{}, error)

NanosToDurationBytes transforms a json byte slice with Nano keys into Duration keys.

func NanosToDurationMap

func NanosToDurationMap(input map[string]interface{}) (map[string]interface{}, error)

NanosToDurationMap transforms keys with Nanos into Duration.

func NewHTTPClient

func NewHTTPClient(o HTTPClientOptions) *http.Client

NewHTTPClient constructs a new HTTP Client.

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, data interface{}, logger *zap.Logger)

WriteJSONResponse writes generic data to the ResponseWriter

func WriteProtoMsgJSONResponse

func WriteProtoMsgJSONResponse(w http.ResponseWriter, data proto.Message, logger *zap.Logger)

WriteProtoMsgJSONResponse writes a protobuf message to the ResponseWriter. This uses jsonpb for json marshalling, which encodes fields with default values, even with the omitempty tag.

func WriteUninitializedResponse

func WriteUninitializedResponse(w http.ResponseWriter, logger *zap.Logger)

WriteUninitializedResponse writes a protobuf message to the ResponseWriter

Types

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse is a generic response for an HTTP error.

type HTTPClientOptions

type HTTPClientOptions struct {
	RequestTimeout     time.Duration `yaml:"requestTimeout"`
	ConnectTimeout     time.Duration `yaml:"connectTimeout"`
	KeepAlive          time.Duration `yaml:"keepAlive"`
	IdleConnTimeout    time.Duration `yaml:"idleConnTimeout"`
	MaxIdleConns       int           `yaml:"maxIdleConns"`
	DisableCompression bool          `yaml:"disableCompression"`
}

HTTPClientOptions specify HTTP Client options.

func DefaultHTTPClientOptions

func DefaultHTTPClientOptions() HTTPClientOptions

DefaultHTTPClientOptions returns default options.

type ParseError

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

ParseError is the error from parsing requests

func NewParseError

func NewParseError(inner error, code int) *ParseError

NewParseError creates a new parse error

func (*ParseError) Code

func (e *ParseError) Code() int

Code returns the parse error type

func (*ParseError) Error

func (e *ParseError) Error() string

Error returns the error string

func (*ParseError) Inner

func (e *ParseError) Inner() error

Inner returns the error object

Directories

Path Synopsis
Package cors handles cross-origin HTTP requests (CORS).
Package cors handles cross-origin HTTP requests (CORS).

Jump to

Keyboard shortcuts

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