util

package
v0.0.0-...-b9fdcee Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: Apache-2.0, BSD-2-Clause, MIT Imports: 9 Imported by: 9

Documentation

Overview

Copyright © 2017 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: BSD-2-Clause

Copyright © 2017 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: BSD-2-Clause

Copyright © 2017 VMware, Inc. All Rights Reserved. SPDX-License-Identifier: BSD-2-Clause

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = errors.New("not found")
	ErrAlreadyExists   = errors.New("already exists")
	ErrInputValidation = errors.New("input validation error")
	ErrUnauthorized    = errors.New("unauthorized error")
	ErrInternal        = errors.New("internal error")
	ErrBadConfig       = errors.New("bad configuration")
)

Functions

func CheckPort

func CheckPort(port int) error

func HttpStatus

func HttpStatus(err error) int

func JSONPrettyPrint

func JSONPrettyPrint(v interface{}) (string, error)

func Memzero

func Memzero(buf []byte)

func NewUUID

func NewUUID() string

func ReadCertificate

func ReadCertificate(filename string) (*x509.Certificate, error)

func ReadRSAPrivateKey

func ReadRSAPrivateKey(filename string) (*rsa.PrivateKey, error)

func ReadRSAPublicKey

func ReadRSAPublicKey(filename string) (*rsa.PublicKey, error)

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, e error) error

func WriteErrorStatus

func WriteErrorStatus(w http.ResponseWriter, e error)

func WriteResponse

func WriteResponse(w http.ResponseWriter, v interface{}, statusCode int) error

func WriteStatus

func WriteStatus(w http.ResponseWriter, statusCode int)

Types

type HttpFilterManager

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

HttpFilterManager holds a chain of pre-filters and a chain of post-filters, and can be used to build a request/response pipeline from the filters and a main handler (see BuildPipeline).

func NewHttpFilterManager

func NewHttpFilterManager() *HttpFilterManager

func (*HttpFilterManager) AddPostFilter

func (fm *HttpFilterManager) AddPostFilter(f PostHttpFilter) *HttpFilterManager

func (*HttpFilterManager) AddPreFilter

func (fm *HttpFilterManager) AddPreFilter(f PreHttpFilter) *HttpFilterManager

func (*HttpFilterManager) BuildPipeline

func (fm *HttpFilterManager) BuildPipeline(handler http.Handler) http.Handler

BuildPipeline builds an returns http.Handler that first invoked the chain of pre-handlers, then invokes the provided handler and finally invoked the chain of post-handlers in reverse order.

type PostHttpFilter

type PostHttpFilter interface {
	HandlePost(w http.ResponseWriter, r *http.Request) bool
}

PostHttpFilter processes a response after its request has been processed by the main request router and returns true if the next filter in the chain should be invoked.

type PreHttpFilter

type PreHttpFilter interface {
	HandlePre(w http.ResponseWriter, r *http.Request) *http.Request
}

PreHttpHandler processses a request before it gets handed of to the main request router and returns the original request or a modified request if the next filter in the chain should be invoked; nil otherwise

Jump to

Keyboard shortcuts

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