httputils

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: Apache-2.0 Imports: 10 Imported by: 10

Documentation

Index

Constants

View Source
const InLimit = 10 * (1 << 20)

Variables

This section is empty.

Functions

func DoHandleData added in v1.0.0

func DoHandleData(ct string, data []byte) http.HandlerFunc

DoHandleData returns an http.HandleFunc that serves a data chunk with a specified content-type.

func DoHandleJSON added in v1.0.0

func DoHandleJSON(v interface{}) http.HandlerFunc

DoHandleJSON returns an http.HandleFunc that serves a data chunk with a specified content-type.

func DoHandleJSONData added in v1.0.0

func DoHandleJSONData(data []byte) http.HandlerFunc

DoHandleJSONData returns an http.HandleFunc that serves a JSON-encoded data chunk.

func ErrorToStatus added in v1.0.0

func ErrorToStatus(err error) int

func IsValidURL added in v1.0.0

func IsValidURL(rawURL string) error

IsValidURL checks if a given URL is a valid URL with a host and a http or http scheme.

func LimitReadAll

func LimitReadAll(in io.Reader, limit int) ([]byte, error)

func NormalizeRemoteBaseURL

func NormalizeRemoteBaseURL(mattermostSiteURL, remoteURL string) (string, error)

func ProcessResponseError

func ProcessResponseError(w http.ResponseWriter, resp *http.Response, err error) bool

func ReadAndClose

func ReadAndClose(in io.ReadCloser) ([]byte, error)

func WriteErrorIfNeeded added in v1.2.0

func WriteErrorIfNeeded(w http.ResponseWriter, err error)

func WriteJSON

func WriteJSON(w http.ResponseWriter, v interface{}) error

WriteJSON encodes and writes out an object, with a 200 response status code.

func WriteJSONStatus

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

WriteJSONStatus encodes and writes out an object, with a custom response status code.

Types

type Handler

type Handler struct {
	*mux.Router
}

func NewHandler

func NewHandler() *Handler

type LimitReadCloser

type LimitReadCloser struct {
	ReadCloser io.ReadCloser
	TotalRead  utils.ByteSize
	Limit      utils.ByteSize
	OnClose    func(*LimitReadCloser) error
}

func (*LimitReadCloser) Close

func (r *LimitReadCloser) Close() error

func (*LimitReadCloser) Read

func (r *LimitReadCloser) Read(data []byte) (int, error)

Jump to

Keyboard shortcuts

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