httpextra

package
v0.0.0-...-244c41e Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const LocalDevServerEnvVarName = "LOCAL_DEV_SERVER_URL"

LocalDevServerEnvVarName is the environment variable name for the dev server For example the standard create-react-app webpack server, this value will be: "http://localhost:3000/" If using create-react-app, you can also add BROWSER=0 to the start of the npm/yarn "start" task, and that will prevent a browser tab being automatically opened.

Variables

This section is empty.

Functions

func AllMethods

func AllMethods() []string

func CheckResponseCode

func CheckResponseCode(expected, got int) error

func CorsAllowAnythingMiddleware

func CorsAllowAnythingMiddleware() func(http.Handler) http.Handler

CorsAllowAnythingMiddleware allows any request from anywhere

func CorsCustomMiddleware

func CorsCustomMiddleware(config CustomCors) func(http.Handler) http.Handler

CorsAllowAnythingMiddleware allows any request from anywhere

func DecodeJSONDataResponse

func DecodeJSONDataResponse(reader io.Reader, dest interface{}) errorsx.Error

func GetBodyOrErrorMsg

func GetBodyOrErrorMsg(resp *http.Response) string

GetBodyOrErrorMsg returns the response body, or a string with the error message when getting the response body. It's useful for logging information, when receiving an error.

func NewLocalDevServerProxy

func NewLocalDevServerProxy() (http.Handler, errorsx.Error)

NewLocalDevServerProxy creates a http handler to proxy a local dev server setup

func NewServerWithTimeouts

func NewServerWithTimeouts() *http.Server

NewServerWithTimeouts returns an http server with some sensible timeouts

func RemoveGzip

func RemoveGzip(resp *http.Response) (io.ReadCloser, error)

Types

type CustomCors

type CustomCors struct {
	AllowOrigin  []string // use ["*"] for all
	AllowHeaders []string // use ["*"] for all
	AllowMethods []string
}

type DataResponse

type DataResponse struct {
	Data interface{} `json:"data"`
}

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer is implemented by http.DefaultClient

type MockDoer

type MockDoer struct {
	DoFunc func(req *http.Request) (*http.Response, error)
}

func (*MockDoer) Do

func (d *MockDoer) Do(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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