restils

package module
v0.0.0-...-73de94d Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 16 Imported by: 0

README

restils

Go package containing a collection of RESTful utilities

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaseInsensitiveKeyMapJoin

func CaseInsensitiveKeyMapJoin[value any](
	primary, addOn map[string]value,
) map[string]value

func DoHTTPCommunication

func DoHTTPCommunication(
	ctx context.Context,
	url, httpMethod string,
	reqBody io.Reader,
	reqHeaders map[string]string,
) (statusCode int, respBody []byte, err error)

DoHTTPCommunication is a thin-wrapper over basic HTTP communication.

Parameters: - url: url to send request to. - httpMethod: HTTP method used to send request. - reqBody: message body to send with HTTP request. (if nil, then no body is sent) - reqHeaders: Headers to set with HTTP request.

Returns: - statusCode: HTTP status code. - respBody: Response body. - err: error.

func DoHTTPStreamedCommunication

func DoHTTPStreamedCommunication(
	ctx context.Context,
	url, httpMethod string,
	reqBody io.Reader,
	reqHeaders map[string]string,
) (statusCode int, respBody io.ReadCloser, err error)

DoHTTPStreamedCommunication is a thin-wrapper over basic HTTP communication where the response is not read by the function but rather the caller is responsible the body contents and closing the reader when done.

Parameters: - url: url to send request to. - httpMethod: HTTP method used to send request. - reqBody: message body to send with HTTP request. (if nil, then no body is sent) - reqHeaders: Headers to set with HTTP request.

Returns: - statusCode: HTTP status code. - respBody: Response body reader. (only set when there is no error) - err: error.

func DoProtoHTTPCommunication

func DoProtoHTTPCommunication(
	ctx context.Context,
	url, httpMethod string,
	req protoreflect.ProtoMessage,
	reqHeaders map[string]string,
	resp protoreflect.ProtoMessage,
) (statusCode int, err error)

DoProtoHTTPCommunication does HTTP communication over proto defined messages.

Parameters: - url: URL to send request to. - httpMethod: HTTP method used to send request. - req: Proto message to be used as request body. (if nil, then no body is sent) - reqHeaders: Headers to set with HTTP request. - resp: on success, the response is decoded and set to this. (if nil, then no response body is expected)

Returns: - statusCode: HTTP status code. - err: error.

func DownloadAndUpload

func DownloadAndUpload(
	ctx context.Context,
	downloadURL string,
	downloadHeaders map[string]string,
	uploadURL string,
	uploadHeaders map[string]string,
) error

Uses Get to download and PUT to upload

func DownloadURLToPath

func DownloadURLToPath(
	ctx context.Context,
	filePath string,
	downloadURL string,
) error

func ExtractPayloadFromZip

func ExtractPayloadFromZip(
	zipfilePath string,
	filename string,
) ([]byte, error)

func ProcessLongRunningOperationToCompletion

func ProcessLongRunningOperationToCompletion[
	Req protoreflect.ProtoMessage,
	Resp protoreflect.ProtoMessage,
](
	ctx context.Context,
	l *LongrunningOperation[Req, Resp],
) error

func RetryFunc

func RetryFunc(
	timeout time.Duration,
	fn func() error,
) error

Types

type LongrunningOperation

type LongrunningOperation[Req, Resp protoreflect.ProtoMessage] struct {
	OperationName  string
	OperationError error
	OperationDone  bool

	Request  Req
	Response Resp
	// contains filtered or unexported fields
}

func CreateLongrunningOperation

func CreateLongrunningOperation[Req, Resp protoreflect.ProtoMessage](
	trigger func(ctx context.Context, req Req) (*longrunningpb.Operation, error),
	get func(ctx context.Context, req *longrunningpb.GetOperationRequest) (*longrunningpb.Operation, error),
	req Req,
) *LongrunningOperation[Req, Resp]

func (*LongrunningOperation[Req, Resp]) GetRequest

func (l *LongrunningOperation[Req, Resp]) GetRequest() Req

func (*LongrunningOperation[Req, Resp]) GetResponse

func (l *LongrunningOperation[Req, Resp]) GetResponse() Resp

func (*LongrunningOperation[Req, Resp]) MarshalJSON

func (l *LongrunningOperation[Req, Resp]) MarshalJSON() ([]byte, error)

func (*LongrunningOperation[Req, Resp]) Process

func (l *LongrunningOperation[Req, Resp]) Process(ctx context.Context) (bool, error)

func (*LongrunningOperation[Req, Resp]) UnmarshalJSON

func (l *LongrunningOperation[Req, Resp]) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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