request

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BinaryMessage string = "binary"
	TextMessage   string = "text"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPReq

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

func NewHTTPReq

func NewHTTPReq(ctx context.Context, method, url string, body []byte, reqID int64) *HTTPReq

NewHTTPReq creates a new HTTPReq instance with the specified method, URL, and body. It takes three parameters: ctx of type context.Context, method of type string, and url of type string. It also takes body of type []byte which represents the request payload. It returns a pointer to an HTTPReq struct initialized with the provided method, URL, and body.

func (*HTTPReq) AddHeader

func (r *HTTPReq) AddHeader(key, value string)

AddHeader adds a header key-value pair to the HTTP request. It takes two parameters: key of type string and value of type string. It appends the value to the list of values associated with the key in the headers map.

func (*HTTPReq) Context

func (r *HTTPReq) Context() context.Context

Context returns the context associated with the HTTPReq. It takes no parameters. It returns a context.Context which is the context stored in the HTTPReq.

func (*HTTPReq) Data

func (r *HTTPReq) Data() []byte

Data returns the body of the HTTP request as a byte slice. It takes no parameters. It returns a byte slice containing the body of the HTTP request.

func (*HTTPReq) ID

func (r *HTTPReq) ID() int64

func (*HTTPReq) RoutingKey

func (r *HTTPReq) RoutingKey() string

RoutingKey constructs and returns a routing key string for the HTTP request. It concatenates the HTTP method and URL of the request, separated by a space. It does not return an error.

func (*HTTPReq) ToHTTPRequest

func (r *HTTPReq) ToHTTPRequest() (*http.Request, error)

ToHTTPRequest converts an HTTPReq struct to an *http.Request. It takes no parameters and uses the fields of the HTTPReq struct. It returns a pointer to an http.Request and an error. It returns an error if the http.NewRequestWithContext call fails, such as when the method or URL is invalid.

func (*HTTPReq) WithContext

func (r *HTTPReq) WithContext(ctx context.Context) wasabi.Request

WithContext sets the context for the HTTP request. It takes ctx of type context.Context and returns the modified HTTPReq. This function does not return an error.

type Request

type Request struct {
	Params      map[string]any `json:"params"`
	ID          *int           `json:"req_id"`
	Method      string         `json:"method"`
	PassThrough any            `json:"passthrough"`
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(ctx context.Context, msgType string, data []byte) *Request

NewRequest creates a new Request object based on the provided message type and data. It takes ctx of type context.Context, msgType of type string, and data of type []byte. It returns a pointer to a Request object. If the msgType is BinaryMessage or if the data cannot be unmarshaled into a Request object, it initializes the Request with the provided msgType and data. Otherwise, it unmarshals the data into a Request object and sets the context and data fields.

func (*Request) Context

func (r *Request) Context() context.Context

Context returns the context associated with the Request. It returns a context.Context which is the context stored in the Request.

func (*Request) Data

func (r *Request) Data() []byte

Data returns the data stored in the Request as a byte slice. It returns a byte slice containing the data.

func (*Request) RoutingKey

func (r *Request) RoutingKey() string

RoutingKey returns the routing key for the request. It returns a string which is the method of the request.

func (*Request) WithContext

func (r *Request) WithContext(ctx context.Context) wasabi.Request

WithContext sets the context for the Request and returns the updated Request. It takes ctx of type context.Context. It returns the updated Request with the new context.

Jump to

Keyboard shortcuts

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