Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCommonUserHeaders ¶
func AddCommonUserHeaders(uc common.UserConfig, req *resty.Request)
AddCommonUserHeaders adds all common headers that are user or device specific.
func AddInternalHeaders ¶
func AddInternalHeaders(uc common.UserConfig, req *resty.Request)
AddInternalHeaders adds the common.UserConfig internal headers to the given request
Types ¶
type Opts ¶
type Opts struct { // The OnAfterResponse option sets response middleware OnAfterResponse resty.ResponseMiddleware // BaseURL is the primary URL the client is configured with BaseURL string // The OnBeforeRequest option appends the given request middleware into the before request chain. OnBeforeRequest resty.PreRequestHook // HttpClient represents an http.Client that should be used by the resty client HttpClient *http.Client // UserConfig is a function that returns the user config associated with a Lantern user UserConfig func() common.UserConfig // Timeout represents a time limit for requests made by the web client Timeout time.Duration }
Opts are common options that RESTClient may be configured with
type RESTClient ¶
type RESTClient interface { // Gets a JSON document from the given path with the given querystring parameters, reading the result into target. GetJSON(ctx context.Context, path string, params, target any) error // Post the given parameters as form data and reads the result JSON into target. PostFormReadingJSON(ctx context.Context, path string, params, target any) error // Post the given body as JSON with the given querystring parameters and reads the result JSON into target. PostJSONReadingJSON(ctx context.Context, path string, params, body, target any) error // Get data from server and parse to protoc file GetPROTOC(ctx context.Context, path string, params any, target protoreflect.ProtoMessage) error // PostPROTOC sends a POST request with protoc file and parse the response to protoc file PostPROTOC(ctx context.Context, path string, params, body protoreflect.ProtoMessage, target protoreflect.ProtoMessage) error }
func NewRESTClient ¶
func NewRESTClient(opts *Opts) RESTClient
Construct a REST client using the given SendRequest function
type SendRequest ¶
type SendRequest func(ctx context.Context, method string, path string, params any, body []byte) ([]byte, error)
A function that can send RESTful requests and receive response bodies. If specified, params should be encoded as query params for GET requests and as form data for POST and PUT requests. If specified, the body bytes should be sent as the body for POST and PUT requests. Returns the response body as bytes.
Click to show internal directories.
Click to hide internal directories.