restlib

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: Apache-2.0 Imports: 17 Imported by: 6

Documentation

Overview

Package mock contains testing utilities and mocks shared between packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHeaderParam

func GetHeaderParam(r *http.Request, key string) string

func GetQueryParam

func GetQueryParam(r *http.Request, key string) string

func GetQueryParamForBool added in v0.36.0

func GetQueryParamForBool(r *http.Request, key string) (bool, error)

func GetQueryParamForInt added in v0.36.0

func GetQueryParamForInt(r *http.Request, key string) (int64, error)

func GetQueryParamForTime added in v0.36.0

func GetQueryParamForTime(r *http.Request, key string) (convert.JSONTime, error)

func GetURLParam

func GetURLParam(r *http.Request, key string) string

func GetURLParamForInt added in v0.29.0

func GetURLParamForInt(r *http.Request, key string) int64

func ReadCloser added in v0.26.0

func ReadCloser() *readCloser

ReadCloser returns a mock io.ReadCloser that can be set to return an err when Read is called on it and do nothing when Close is called on it.

func ResponseWriter added in v0.26.0

func ResponseWriter() *responseWriter

ResponseWriter returns a mock ResponseWriter implementing http.ResponseWriter.

func SendHTTPResponse

func SendHTTPResponse(w http.ResponseWriter, httpStatus int, responses ...interface{})

SendHTTPResponse sends the http response to the client

func SetHeaders

func SetHeaders(w http.ResponseWriter, headerMap http.Header)

SetHeaders sets the headers in response

Types

type HTTPResult

type HTTPResult struct {
	HTTPResponse *http.Response
	Body         []byte
	Response     interface{}
}

HTTPResult is the result return by the library

func DoHTTPRequest

func DoHTTPRequest(ctx context.Context, client *http.Client, method string,
	urlString string, body interface{}, required []string,
	okResponse interface{}, errorResponse interface{}) (*HTTPResult, error)

DoHTTPRequest returns HTTPResult

func (*HTTPResult) Error

func (r *HTTPResult) Error() string

Jump to

Keyboard shortcuts

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