Documentation ¶
Index ¶
- Constants
- type HTTPReq
- func (r *HTTPReq) AddHeader(key, value string)
- func (r *HTTPReq) Context() context.Context
- func (r *HTTPReq) Data() []byte
- func (r *HTTPReq) ID() int64
- func (r *HTTPReq) RoutingKey() string
- func (r *HTTPReq) ToHTTPRequest() (*http.Request, error)
- func (r *HTTPReq) WithContext(ctx context.Context) wasabi.Request
- type Request
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) RoutingKey ¶
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 ¶
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.
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 ¶
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 ¶
Context returns the context associated with the Request. It returns a context.Context which is the context stored in the Request.
func (*Request) Data ¶
Data returns the data stored in the Request as a byte slice. It returns a byte slice containing the data.
func (*Request) RoutingKey ¶
RoutingKey returns the routing key for the request. It returns a string which is the method of the request.