Documentation
¶
Overview ¶
Package client is to manage internal HTTP requests and caching
Index ¶
- Constants
- Variables
- func EndRequestWithLog(c echo.Context, err error, responseData interface{}) error
- func ExecuteHttpRequest[B any, T any](client *resty.Client, method string, url string, headers map[string]string, ...) error
- func ForwardRequestToAny(reqPath string, method string, requestBody interface{}) (interface{}, error)
- func SetUseBody(requestBody interface{}) bool
- func UpdateRequestProgress(reqID string, progressData interface{})
- type CacheItem
- type CircuitBreakerState
- type ProgressInfo
- type RequestDetails
- type RequestInfo
Constants ¶
const ( // VeryShortDuration is a duration for very short-term cache VeryShortDuration = 1 * time.Second // ShortDuration is a duration for short-term cache ShortDuration = 2 * time.Second // MediumDuration is a duration for medium-term cache MediumDuration = 5 * time.Second // LongDuration is a duration for long-term cache LongDuration = 10 * time.Second )
const MaxDebugBodyLength = 50000
MaxDebugBodyLength is the maximum length of response body for debug logs
const NoBody = "NOBODY"
NoBody is a constant for empty body
Variables ¶
var RequestMap = sync.Map{}
RequestMap is a map for request details
Functions ¶
func EndRequestWithLog ¶
EndRequestWithLog updates the request details and sends the final response.
func ExecuteHttpRequest ¶
func ExecuteHttpRequest[B any, T any]( client *resty.Client, method string, url string, headers map[string]string, useBody bool, body *B, result *T, cacheDuration time.Duration, ) error
ExecuteHttpRequest performs the HTTP request and fills the result (var requestBody interface{} = nil for empty body)
func ForwardRequestToAny ¶
func ForwardRequestToAny(reqPath string, method string, requestBody interface{}) (interface{}, error)
ForwardRequestToAny forwards the given request to the specified path
func SetUseBody ¶
func SetUseBody(requestBody interface{}) bool
SetUseBody returns false if the given body is NoBody
func UpdateRequestProgress ¶
func UpdateRequestProgress(reqID string, progressData interface{})
UpdateRequestProgress updates the handling status of the request.
Types ¶
type CircuitBreakerState ¶ added in v0.11.10
CircuitBreakerState represents the state of a circuit breaker for a specific request
type ProgressInfo ¶
type ProgressInfo struct {
Title string `json:"title"`
Info interface{} `json:"info"`
Time time.Time `json:"time"`
}
ProgressInfo contains the progress information of a request.
type RequestDetails ¶
type RequestDetails struct {
StartTime time.Time `json:"startTime"` // The time when the request was received by the server.
EndTime time.Time `json:"endTime"` // The time when the request was fully processed.
Status string `json:"status"` // The current status of the request (e.g., "Handling", "Error", "Success").
RequestInfo RequestInfo `json:"requestInfo"` // Extracted information about the request.
ResponseData interface{} `json:"responseData"` // The data sent back in response to the request.
ErrorResponse string `json:"errorResponse"` // A message describing any error that occurred during request processing.
}
RequestDetails contains detailed information about an HTTP request and its processing status.
type RequestInfo ¶
type RequestInfo struct {
Method string `json:"method"` // HTTP method (GET, POST, etc.), indicating the request's action type.
URL string `json:"url"` // The URL the request is made to.
Header map[string]string `json:"header"` // Key-value pairs of the request headers.
Body interface{} `json:"body,omitempty"` // Optional: request body
}
RequestInfo stores the essential details of an HTTP request.
func ExtractRequestInfo ¶
func ExtractRequestInfo(r *http.Request) RequestInfo
ExtractRequestInfo extracts necessary information from http.Request