restlib

package
v0.153.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2021 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 OnRestResultHTTPResult added in v0.69.0

func OnRestResultHTTPResult(ctx context.Context, result *HTTPResult, err error)

OnRestResultHTTPResult is called from generated code when an HTTP result is retrieved. The current implementation of restlib.DoHTTPRequest returns an *HTTPResult as an error when a non- successful status code is received. The implementation of this method relies on this behaviour. to set the rest result in the event of a failed request.

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.

func SetRestResult added in v0.74.0

func SetRestResult(ctx context.Context, result common.RestResult)

SetRestResult the contents of the common.RestResult stored in the context. The RestResult is stored in the context through the common.ProvisionRestResult method. This method is exported so that unit tests can set the rest result with appropriate values as required.

Types

type HTTPRequest added in v0.85.0

type HTTPRequest struct {
	Client                    *http.Client
	Method, URLString         string
	Body                      interface{}
	Required                  []string
	OKResponse, ErrorResponse interface{}
	ExtraHeaders              map[string][]string
}

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, urlString string,
	body interface{},
	required []string,
	okResponse, errorResponse interface{},
) (*HTTPResult, error)

DoHTTPRequest returns HTTPResult.

func DoHTTPRequest2 added in v0.85.0

func DoHTTPRequest2(ctx context.Context, config *HTTPRequest) (*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