client

package
v0.11.16 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package client is to manage internal HTTP requests and caching

Index

Constants

View Source
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
)
View Source
const MaxDebugBodyLength = 50000

MaxDebugBodyLength is the maximum length of response body for debug logs

View Source
const NoBody = "NOBODY"

NoBody is a constant for empty body

Variables

View Source
var RequestMap = sync.Map{}

RequestMap is a map for request details

Functions

func EndRequestWithLog

func EndRequestWithLog(c echo.Context, err error, responseData interface{}) error

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 CacheItem

type CacheItem[T any] struct {
	Response  T
	ExpiresAt time.Time
}

CacheItem is a struct to store cached item

type CircuitBreakerState added in v0.11.10

type CircuitBreakerState struct {
	FailureCount int
	LastFailure  time.Time
	IsOpen       bool
}

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

Jump to

Keyboard shortcuts

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