pub

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package pub is used for the publishing of requests. It contains the options to use in Connector.Publish

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(req *Request) error

Option is used to construct a request in Connector.Publish.

func AddHeader

func AddHeader(name string, value string) Option

AddHeader adds a value to the header of the request. It is appended to any previously added values.

func Baggage

func Baggage(name string, value string) Option

Baggage sets a baggage header of the request. It overwrites any previously set value.

func Body

func Body(body any) Option

Body sets the body of the request. Arguments of type io.Reader, io.ReadCloser, []byte and string are serialized in binary form. url.Values is serialized as form data. All other types are serialized as JSON. The Content-Type Content-Length headers will be set to match the body if they can be determined and unless already set.

func ContentLength

func ContentLength(len int) Option

ContentLength sets the Content-Length header of the request.

func ContentType

func ContentType(contentType string) Option

ContentType sets the Content-Type header.

func CopyHeaders

func CopyHeaders(headers http.Header) Option

CopyHeaders copies all non-Microbus headers from an upstream request.

func DELETE

func DELETE(url string) Option

DELETE sets the method and URL of the request.

func GET

func GET(url string) Option

GET sets the method and URL of the request.

func HEAD(url string) Option

HEAD sets the method and URL of the request.

func Header(name string, value string) Option

Header sets the header of the request. It overwrites any previously set values.

func Method

func Method(method string) Option

Method sets the method of the request.

func Multicast

func Multicast() Option

Multicast indicates that a multiple responses are expected from this request.

func Noop

func Noop() Option

Noop does nothing.

func PATCH

func PATCH(url string) Option

PATCH sets the method and URL of the request.

func POST

func POST(url string) Option

POST sets the method and URL of the request.

func PUT

func PUT(url string) Option

PUT sets the method and URL of the request.

func Query

func Query(args url.Values) Option

Query adds arguments to the request.

func QueryArg

func QueryArg(name string, value any) Option

QueryArg adds the query argument to the request. The same argument may have multiple values.

func QueryString

func QueryString(encodedQueryArgs string) Option

Query adds the encoded query arguments to the request. The same argument may have multiple values.

func URL

func URL(url string) Option

URL sets the URL of the request.

func Unicast

func Unicast() Option

Unicast indicates that a single response is expected from this request.

type Request

type Request struct {
	Method    string
	URL       string
	Header    http.Header
	Body      io.Reader
	Multicast bool
	// contains filtered or unexported fields
}

Request is used to construct an HTTP request that can be sent over the bus. Although technically public, it is used internally and should not be constructed by microservices directly.

func NewRequest

func NewRequest(options ...Option) (*Request, error)

NewRequest constructs a new request from the provided options.

func (*Request) Apply

func (req *Request) Apply(options ...Option) error

Apply the provided options to the request, in order.

func (*Request) Canonical

func (req *Request) Canonical() string

Canonical returns the fully-qualified canonical path of the request, without the query arguments.

type Response

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

Response is a union of an http.Response and an error. Only one or the other is valid

func NewErrorResponse

func NewErrorResponse(err error) *Response

NewErrorResponse creates a new response containing an error

func NewHTTPResponse

func NewHTTPResponse(res *http.Response) *Response

NewResponse creates a new response containing an http.Response

func (*Response) Get

func (r *Response) Get() (*http.Response, error)

Get returns the http.Response or error stored in the composite Response

Jump to

Keyboard shortcuts

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