corehooks

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EncodeRequestBody = request.Hook{Name: "core.EncodeRequestBody", Fn: func(r *request.Request) {
	if r.Params == nil {
		return
	}

	buf := new(bytes.Buffer)
	if err := jsoniter.NewEncoder(buf).Encode(r.Params); err != nil {
		r.Error = err
		return
	}

	r.Request.Body = io.NopCloser(buf)

}}

EncodeRequestBody converts the value in r.Params into an io reader and adds it to the http.Request instance

View Source
var LogHTTPRequest = request.Hook{Name: "core.LogHTTPRequest", Fn: logRequest}

LogHTTPRequest is a hook to log the HTTP request sent to a service. If log level matches request.LogDebugWithHTTPBody, the request body will be included.

View Source
var ResolveEndpoint = request.Hook{Name: "core.ResolveEndpoint", Fn: func(r *request.Request) {
	r.Config.Endpoint = AddScheme(r.Config.Endpoint, r.Config.DisableSSL)
}}
View Source
var SendHook = request.Hook{Name: "core.Send", Fn: func(r *request.Request) {
	sender := sendFollowRedirects
	if r.Config.DisableFollowRedirects {
		sender = sendWithoutFollowRedirects
	}

	if r.Request.Body == request.NoBody {

		reqOrig, reqCopy := r.Request, *r.Request
		reqCopy.Body = nil
		r.Request = &reqCopy
		defer func() {
			r.Request = reqOrig
		}()
	}

	var err error
	r.Response, err = sender(r)
	if err != nil {
		handleSendError(r, err)
	}
}}

Functions

func AddScheme

func AddScheme(endpoint string, disableSSL bool) string

AddScheme adds the HTTP or HTTPS schemes to an endpoint URL if there is no scheme. If disableSSL is true, HTTP will set HTTP instead of the default HTTPS.

If disableSSL is set, it will only set the URL's scheme if the URL does not contain a scheme.

func DefaultHooks

func DefaultHooks() request.Hooks

func SetBasicAuth

func SetBasicAuth(username, password string) request.Hook

SetBasicAuth modifies the http.Request headers and adds basic auth credentials

func SetHTTPClient

func SetHTTPClient(client *http.Client) request.Hook

SetHTTPClient sets the http.Client to be used for requests. Sets a default http.Client if none is provided with a timeout of 30 seconds.

func SetRequestID

func SetRequestID(fn ...func() string) request.Hook

SetRequestID will set a default request id to the request if no id generator function is given

Types

type RetryHook

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

func NewRetryer

func NewRetryer() RetryHook

func (*RetryHook) Close

func (r *RetryHook) Close() request.Hook

Close stops the timer. Call close as a complete hook to ensure the timer is stopped.

func (*RetryHook) Retry

func (r *RetryHook) Retry() request.Hook

Jump to

Keyboard shortcuts

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