Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Post ¶
func (c *Client) Post(ctx context.Context, target string, payload []byte, secrets []string) ([]byte, error)
Post sends a signed HTTP POST request with a JSON payload to a user-defined webhook endpoint.
This method performs the following steps:
- Validates the target URL and enforces HTTP/HTTPS schemes.
- Signs the payload using one or more shared secrets to generate HMAC signatures.
- Adds a timestamp and the generated signatures to the "X-Signature" header to ensure integrity and support replay protection.
- Sends the HTTP POST request with appropriate headers, including User-Agent and Content-Type.
- Limits the response body size to prevent resource exhaustion.
- Returns the response body if the request succeeds with a 2xx status code.
Parameters:
- ctx: The context for request cancellation and timeout control.
- target: The webhook endpoint URL.
- payload: The JSON payload to send.
- secrets: A list of shared secrets used for HMAC payload signing.
Returns:
- The response body as a byte slice if the request is successful.
- An error if URL validation fails, signing fails, the HTTP request fails, or a non-2xx response is received.
Click to show internal directories.
Click to hide internal directories.