Documentation
¶
Index ¶
- Constants
- Variables
- func DecoratorTimer(fn func() error)
- type CallbackErr
- type CallbackExtra
- type CallbackOk
- type Client
- func DELETE[T any](path string, params H, data any, headers ...H) *Client[T]
- func Default[T any]() *Client[T]
- func GET[T any](path string, params H, headers ...H) *Client[T]
- func HEAD[T any](path string, params H, headers ...H) *Client[T]
- func New[T any]() *Client[T]
- func NewClient() *Client[any]deprecated
- func NewHTTP[T any]() *Client[T]
- func NewREST[T any]() *Client[T]
- func OPTIONS[T any](path string, headers ...H) *Client[T]
- func PATCH[T any](path string, params H, data any, headers ...H) *Client[T]
- func POST[T any](path string, params H, data any, headers ...H) *Client[T]
- func PUT[T any](path string, params H, data any, headers ...H) *Client[T]
- func (c *Client[T]) Catch(cb CallbackErr) *Client[T]
- func (c *Client[T]) ChalkInt(level level, n int) *Client[T]
- func (c *Client[T]) ChalkObj(level level, obj any) *Client[T]
- func (c *Client[T]) ChalkPrintf(level level, format string, args ...any) *Client[T]
- func (c *Client[T]) ChalkStr(level level, s string) *Client[T]
- func (c *Client[T]) Cookie(name string) (*http.Cookie, error)
- func (c *Client[T]) Cookies() []*http.Cookie
- func (c *Client[T]) Data() T
- func (c *Client[T]) DefineOkCode(code int) *Client[T]
- func (c *Client[T]) Echo()
- func (c *Client[T]) EchoBenchmark() (int, int64)
- func (c *Client[T]) EchoCode() (int, int)
- func (c *Client[T]) EchoMessage() (string, string)
- func (c *Client[T]) EchoMode() string
- func (c *Client[T]) EchoProto() string
- func (c *Client[T]) EchoQPS() float64
- func (c *Client[T]) EchoTime() (time.Duration, time.Time)
- func (c *Client[T]) EchoURL() (string, string)
- func (c *Client[T]) FilterUrlSlash() *Client[T]
- func (c *Client[T]) Finally(cb CallbackExtra[T], printLog ...bool)
- func (c *Client[T]) Header(key string) string
- func (c *Client[T]) Headers() http.Header
- func (c *Client[T]) Optional(fns ...ClientFunc[T]) *Client[T]
- func (c *Client[T]) Query(q string) string
- func (c *Client[T]) QueryParams() SMap
- func (c *Client[T]) RegisterJsonLib(lib JSONLibrary) *Client[T]
- func (c *Client[T]) Send() *Client[T]
- func (c *Client[T]) SetAccept(accept string) *Client[T]
- func (c *Client[T]) SetBaseURI(baseUri string) *Client[T]
- func (c *Client[T]) SetBasicAuth(username, password string) *Client[T]
- func (c *Client[T]) SetBearerAuth(token string) *Client[T]
- func (c *Client[T]) SetContentType(ct string) *Client[T]
- func (c *Client[T]) SetCookie(cookie *http.Cookie) *Client[T]
- func (c *Client[T]) SetCookies(cookies []*http.Cookie) *Client[T]
- func (c *Client[T]) SetEndpoint(endpoint string) *Client[T]
- func (c *Client[T]) SetHeader(key, value string) *Client[T]
- func (c *Client[T]) SetHeaders(headers H) *Client[T]
- func (c *Client[T]) SetHost(host string) *Client[T]
- func (c *Client[T]) SetJsonPayload(data H) *Client[T]
- func (c *Client[T]) SetLanguage(lang string) *Client[T]
- func (c *Client[T]) SetMethod(method string) *Client[T]
- func (c *Client[T]) SetPayload(data any) *Client[T]
- func (c *Client[T]) SetQueryParam(key, value string) *Client[T]
- func (c *Client[T]) SetQueryParams(params H) *Client[T]
- func (c *Client[T]) SetRequest(method, path string, pathParams ...string) *Client[T]
- func (c *Client[T]) SetSchema(scheme string) *Client[T]
- func (c *Client[T]) SetURL(scheme, host, baseUri, endpoint string) *Client[T]
- func (c *Client[T]) SetUserAgent(ua string) *Client[T]
- func (c *Client[T]) Then(cb CallbackOk[T]) *Client[T]
- func (c *Client[T]) ToJson(v any) error
- func (c *Client[T]) ToggleMode() *Client[T]
- func (c *Client[T]) Unwrap() (*Client[T], string)
- func (c *Client[T]) UsePostHooks(funcs ...afterResponse[T])
- func (c *Client[T]) UsePreHooks(funcs ...beforeRequest[T])
- type ClientFunc
- func Lambda[T any](f func(*Client[T])) ClientFunc[T]
- func WithDisabledRestMode[T any]() ClientFunc[T]deprecated
- func WithFilterSlash[T any](filterSlash bool) ClientFunc[T]deprecated
- func WithIsDebug[T any](isDebug bool) ClientFunc[T]
- func WithModifySuccessCode[T any](code int) ClientFunc[T]deprecated
- func WithRegisterJsonLibrary[T any](lib JSONLibrary) ClientFunc[T]
- func WithSkipTLS[T any](skipTLS bool) ClientFunc[T]
- func WithTimeout[T any](timeout time.Duration) ClientFunc[T]
- func WithUseLogger[T any](enabled bool) ClientFunc[T]
- type Config
- type Context
- type Exception
- type ExecMethod
- type GoJSONLibrary
- type H
- type JSONLibrary
- type Meta
- type NativeJSONLibrary
- type RESTFulResp
- type Response
- type SMap
Examples ¶
Constants ¶
const ( // MethodGet HTTP method MethodGet = "GET" // MethodPost HTTP method MethodPost = "POST" // MethodPut HTTP method MethodPut = "PUT" // MethodDelete HTTP method MethodDelete = "DELETE" // MethodPatch HTTP method MethodPatch = "PATCH" // MethodHead HTTP method MethodHead = "HEAD" // MethodOptions HTTP method MethodOptions = "OPTIONS" )
const ( // ProtocolHttp HTTP protocol ProtocolHttp = "http" // ProtocolHttps HTTPS protocol ProtocolHttps = "https" )
const ( // RootURL an alias for signSlash RootURL = signSlash // Placeholder an alias for signHorizontal Placeholder = signHorizontal )
const ( // OkCode Predefined default success response codes OkCode = 0 // FailCode Predefine default failure response codes FailCode = 50000 )
const ( // TimeoutShort Short timeout duration (10 seconds) TimeoutShort = 10 * time.Second // TimeoutMedium Medium timeout duration (30 seconds) TimeoutMedium = 30 * time.Second // TimeoutLong Long timeout duration (60 seconds) TimeoutLong = 60 * time.Second )
const ( // AuthTypeBasic Basic authentication type AuthTypeBasic = "Basic" // AuthTypeBearer Bearer authentication type AuthTypeBearer = "Bearer" )
const ( // LocaleEn English locale LocaleEn = "en-US,en;q=0.9" // LocaleZh Chinese locale LocaleZh = "zh-CN,zh;q=0.9" )
const ( // PlainTextType Plain text content type PlainTextType = "text/plain; charset=utf-8" // JsonContentType JSON content type JsonContentType = "application/json" // FormContentType Form data content type FormContentType = "application/x-www-form-urlencoded" )
const ( // LogLevelSuccess represents logs at the SUCCESS level LogLevelSuccess level = "SUCCESS" // LogLevelFail represents logs at the FAIL level LogLevelFail level = "FAIL" // LogLevelPanic represents logs at the PANIC level LogLevelPanic level = "PANIC" // LogLevelInfo represents logs at the INFO level LogLevelInfo level = "INFO" // LogLevelWarn represents logs at the WARN level LogLevelWarn level = "WARN" // LogLevelDebug represents logs at the DEBUG level LogLevelDebug level = "DEBUG" )
Log levels
Variables ¶
var ( HeaderAcceptKey = http.CanonicalHeaderKey("Accept") HeaderLocationKey = http.CanonicalHeaderKey("Location") HeaderUserAgentKey = http.CanonicalHeaderKey("User-Agent") HeaderContentTypeKey = http.CanonicalHeaderKey("Content-Type") HeaderContentLengthKey = http.CanonicalHeaderKey("Content-Length") HeaderContentLanguageKey = http.CanonicalHeaderKey("Content-Language") HeaderContentEncodingKey = http.CanonicalHeaderKey("Content-Encoding") HeaderAuthorizationKey = http.CanonicalHeaderKey("Authorization") )
var ( // Title is the name of the project. Title string = "Gloria" // Version is the version number of the application. Version string = "1.0.0" // BuildTime is the build time of the application. // Better practice: go build -ldflags "-X main.BuildTime=$(date '+%Y-%m-%d %H:%M:%S')" main.go BuildTime string = "" // GitHash is the commit hash of the application's Git repository. GitHash string = "" )
var ( // QueryMethods Method list in a String Slice QueryMethods = []string{ MethodGet, MethodPost, MethodPut, MethodDelete, MethodPatch, MethodHead, MethodOptions, } )
Functions ¶
func DecoratorTimer ¶
func DecoratorTimer(fn func() error)
DecoratorTimer a decorator for timing functions to test api performance.
Types ¶
type CallbackErr ¶
type CallbackErr func(e *Exception)
type CallbackExtra ¶
type CallbackOk ¶
type CallbackOk[T any] func(data T)
type Client ¶
type Client[T any] struct { // context Context *Context // request metadata Meta *Meta // request settings Config *Config // intercepted error Exception *Exception // expandable body Result *RESTFulResp[T] // contains filtered or unexported fields }
func DELETE ¶
DELETE is a shorthand function for creating a DELETE request with the specified path, query parameters, request body data, and headers. It returns a new client instance configured for a DELETE request.
func Default ¶
Default function returns a basic default template.
Preset parameters:
- Debug: false
- Logger: true
- OkCode: 0
- TLS: skip
- Timeout: 30s
- RestMode: true
Inject default middleware:
- set Accept: application/json
- set Content-Type: application/json
- set Content-Language: en-US,en;q=0.9
- set User-Agent: - actual environment
func GET ¶
GET is a shorthand function for creating a GET request with the specified path, query parameters, and headers. It returns a new client instance configured for a GET request.
func HEAD ¶
HEAD is a shorthand function for creating a HEAD request with the specified path, query parameters, request body data, and headers. It returns a new client instance configured for a HEAD request.
func NewHTTP ¶
NewHTTP function returns an empty template initialization (for http mode).
Example (Method1) ¶
// Create an HTTP client with HttpBin response struct client := NewHTTP[HttpBin]() client.SetMethod(MethodGet) client.SetURL(ProtocolHttp, "httpbin.org", "", "/get") client.Send() client.Unwrap() client.Echo()
Example (Method2) ¶
// One line response client, _ := NewHTTP[HttpBin]().SetRequest(MethodGet, "http://httpbin.org/get").Send().Unwrap() fmt.Println(client.Data().Url)
Output: http://httpbin.org/get
func OPTIONS ¶
OPTIONS is a shorthand function for creating an OPTIONS request with the specified path and headers. It returns a new client instance configured for an OPTIONS request.
func PATCH ¶
PATCH is a shorthand function for creating a PATCH request with the specified path, query parameters, request body data, and headers. It returns a new client instance configured for a PATCH request.
func POST ¶
POST is a shorthand function for creating a POST request with the specified path, query parameters, request body data, and headers. It returns a new client instance configured for a POST request.
func PUT ¶
PUT is a shorthand function for creating a PUT request with the specified path, query parameters, request body data, and headers. It returns a new client instance configured for a PUT request.
func (*Client[T]) Catch ¶
func (c *Client[T]) Catch(cb CallbackErr) *Client[T]
Catch sets a callback function to be executed when an exception occurs during the HTTP request. The provided callback function cb is invoked only if an exception exists in the client instance. The cb function is called with the exception object as its argument. After executing the callback function, the client instance is returned.
func (*Client[T]) ChalkInt ¶
ChalkInt writes a log entry with the specified level and integer value. The 'level' parameter represents the log level. The 'n' parameter is the integer to be logged. It returns the updated Client instance.
func (*Client[T]) ChalkObj ¶
ChalkObj writes a log entry with the specified level and object value. It uses reflection to extract the value from the object parameter. The 'level' parameter represents the log level. The 'obj' parameter is the object to be logged. It returns the updated Client instance.
func (*Client[T]) ChalkPrintf ¶
ChalkPrintf writes a formatted log entry with the specified level and arguments. The 'level' parameter represents the log level. The 'format' parameter is the format string for the log message. The 'args' parameter contains the arguments to be formatted. It returns the updated Client instance.
func (*Client[T]) ChalkStr ¶
ChalkStr writes a log entry with the specified level and string value. The 'level' parameter represents the log level. The 's' parameter is the string to be logged. It returns the updated Client instance.
func (*Client[T]) Cookie ¶ added in v0.1.6
Cookie returns the cookie with the specified name from the client's request context. If the cookie is found, it returns the cookie object. If the cookie is not found, it returns an error.
func (*Client[T]) Cookies ¶ added in v0.1.6
Cookies returns the cookies as a []*http.Cookie from the client's request context.
func (*Client[T]) DefineOkCode ¶
func (*Client[T]) EchoBenchmark ¶
func (*Client[T]) EchoMessage ¶
func (*Client[T]) FilterUrlSlash ¶ added in v0.1.4
Note: The FilterUrlSlash method needs to be called before the SetURL or SetRequest method.
func (*Client[T]) Finally ¶
func (c *Client[T]) Finally(cb CallbackExtra[T], printLog ...bool)
Finally function is a flexible custom callback function with checkpoint functionality.
func (*Client[T]) Header ¶ added in v0.1.6
Header returns the value of the specified header key from the client's request context.
func (*Client[T]) Headers ¶ added in v0.1.6
Headers returns the headers as a http.Header from the client's request context.
func (*Client[T]) Optional ¶
func (c *Client[T]) Optional(fns ...ClientFunc[T]) *Client[T]
Optional is a method that allows applying optional configurations to the client instance. It accepts a variadic parameter fns, which represents a list of client functions to be applied. Each function takes the client instance as a parameter and applies specific configurations or modifications to it. The method iterates over the list of functions and calls each function with the client instance as an argument. After applying all the functions, it returns the modified client instance.
func (*Client[T]) Query ¶ added in v0.1.6
Query returns the value of the specified query parameter from the client instance.
func (*Client[T]) QueryParams ¶ added in v0.1.6
QueryParams returns the query parameters as a SMap from the client instance.
func (*Client[T]) RegisterJsonLib ¶ added in v0.1.5
func (c *Client[T]) RegisterJsonLib(lib JSONLibrary) *Client[T]
Note: Please implement the JSONLibrary interface definition yourself.
func (*Client[T]) SetAccept ¶
SetAccept sets the value of the "Accept" header for the request. It takes an `accept` parameter, which is a string representing the value of the "Accept" header. This method allows specifying the desired media type for the response. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
client.SetAccept("application/json")
func (*Client[T]) SetBaseURI ¶
SetBaseURI sets the base URI for the client instance.
This method is called by the SetURL method to set the complete URL for the client instance.
See SetURL.
func (*Client[T]) SetBasicAuth ¶
SetBasicAuth sets the Basic Authentication credentials for the request. It takes a `username` and `password` as parameters and sets them as the Basic Authentication credentials in the `Client` instance. The `username` parameter represents the username for the Basic Authentication. The `password` parameter represents the password for the Basic Authentication. This method replaces any existing authorization credentials in the `Client` instance with the new Basic Authentication credentials. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
client.SetBasicAuth("username", "password")
func (*Client[T]) SetBearerAuth ¶
SetBearerAuth sets the Bearer Token for the request. It takes a `token` as a parameter and sets it as the Bearer Token in the `Client` instance. The `token` parameter represents the Bearer Token for the authentication. This method replaces any existing authorization credentials in the `Client` instance with the new Bearer Token. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
client.SetBearerAuth("your-token")
func (*Client[T]) SetContentType ¶
SetContentType sets the value of the "Content-Type" header for the request. It takes a `ct` parameter, which is a string representing the value of the "Content-Type" header. This method allows specifying the media type of the request payload. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
client.SetContentType("application/json")
func (*Client[T]) SetCookie ¶
SetCookie adds a cookie to the request headers. It takes a `cookie` parameter, which is a pointer to an `http.Cookie` representing the cookie to be added. This method allows adding a cookie to the request headers. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
cookie := &http.Cookie{
Name: "session",
Value: "1234567890",
}
client.SetCookie(cookie)
func (*Client[T]) SetCookies ¶
SetCookies sets the cookies for the request headers. It takes a `cookies` parameter, which is a slice of pointers to `http.Cookie` representing the cookies to be set. This method allows setting multiple cookies for the request headers. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
cookie1 := &http.Cookie{
Name: "session",
Value: "1234567890",
}
cookie2 := &http.Cookie{
Name: "user",
Value: "john.doe",
}
cookies := []*http.Cookie{cookie1, cookie2}
client.SetCookies(cookies)
func (*Client[T]) SetEndpoint ¶
SetEndpoint sets the API endpoint for the client instance to the specified endpoint.
This method is called by the SetURL method to set the complete URL for the client instance.
See SetURL.
func (*Client[T]) SetHeader ¶
SetHeader sets a custom header for the request. It takes a `key` and `value` as parameters and adds the header to the `Client` instance. The `key` parameter represents the header key, and the `value` parameter represents the header value. This method allows adding custom headers to the request. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
client.SetHeader("Content-Type", "application/json")
func (*Client[T]) SetHeaders ¶
SetHeaders sets multiple custom headers for the request. It takes a `headers` parameter, which is a map[string]string representing the headers to be set. Each key-value pair in the `headers` map corresponds to a header key and value, respectively. This method allows setting multiple custom headers at once. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
headers := map[string]any{
"Content-Type": "application/json",
"Authorization": "Bearer <token>",
}
client.SetHeaders(headers)
func (*Client[T]) SetHost ¶
SetHost sets the host URL for the client instance.
This method is called by the SetURL method to set the complete URL for the client instance.
See SetURL.
func (*Client[T]) SetJsonPayload ¶
SetJsonPayload sets the JSON payload for the request. It takes a `data` parameter, which is a map[string]any representing the JSON data to be sent in the request body. This method is used for making JSON-encoded POST or PUT requests. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
payload := map[string]interface{}{
"name": "John Doe",
"email": "john.doe@example.com",
}
client.SetJsonPayload(payload)
func (*Client[T]) SetLanguage ¶
SetLanguage sets the value of the "Accept-Language" header for the request. It takes a `lang` parameter, which is a string representing the value of the "Accept-Language" header. This method allows specifying the preferred language for the response. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
client.SetLanguage("en-US")
func (*Client[T]) SetMethod ¶
SetMethod sets the HTTP method for the client instance to the specified method. This method must be one of the supported methods: GET, POST, PUT, PATCH, DELETE, HEAD, or OPTIONS.
If an unsupported method is provided, this method will panic with an error message indicating the supported methods.
Example usage:
client.SetMethod("GET")
func (*Client[T]) SetPayload ¶
SetPayload sets the payload for the request. It takes a `data` parameter of any type representing the data to be sent in the request body. This method is used for making generic POST or PUT requests. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
payload := "Hello, World!" client.SetPayload(payload)
func (*Client[T]) SetQueryParam ¶
SetQueryParam sets a query parameter for the request. It takes a key and value as parameters and adds them to the params map of the Client instance. It returns a pointer to the Client instance, allowing for method chaining.
Example usage:
client.SetQueryParam("key", "value")
func (*Client[T]) SetQueryParams ¶
SetQueryParams sets multiple query parameters for the request. It takes a `params` map as a parameter and converts it to the `SMap` type, which is used to store query parameters in the `Client` instance. The `params` map contains key-value pairs where the keys represent the query parameter names and the values represent the query parameter values. This method replaces any existing query parameters in the `params` map of the `Client` instance with the new ones. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
params := H{"key1": "value1", "key2": "value2"}
client.SetQueryParams(params)
func (*Client[T]) SetRequest ¶
SetRequest sets the request method and path for the client. It also supports dynamic routing by replacing path parameters with actual values. The method parameter specifies the HTTP method (e.g., "GET", "POST", "PUT", etc.). The path parameter specifies the request path with optional path parameters. The pathParams parameter is an optional variadic parameter that contains the values to replace the path parameters in the request path. It returns the modified client instance.
Dynamic Routing: The SetRequest function supports dynamic routing by allowing you to replace path parameters in the request path with actual values. If there is only one path parameter, you can use the placeholder ":id" in the path. If there are two path parameters, the first one should be replaced with ":id" and the second one with ":sid".
Example:
client := NewClient()
client.SetRequest("GET", "/users/:id", "123")
client.SetRequest("POST", "/users/:id/:sid", "123", "456")
In the above example, the first SetRequest call sets the request method to "GET" and the request path to "/users/123". The second SetRequest call sets the request method to "POST" and the request path to "/users/123/456".
Note: The SetRequest function currently supports a maximum of two dynamic routing parameters. If more than two path parameters are provided, a panic will occur.
func (*Client[T]) SetSchema ¶
SetSchema sets the protocol scheme for the client instance.
This method is called by the SetURL method to set the complete URL for the client instance.
See SetURL.
func (*Client[T]) SetURL ¶
SetURL sets the scheme, host, base URI, and endpoint for the client instance. These values will be used to construct the URL for the request.
The scheme parameter specifies the protocol scheme for the request, such as "http" or "https". The host parameter specifies the hostname or IP address of the server to send the request to. The baseUri parameter specifies the base URI for the API endpoint, such as "/v1" or "/api". The endpoint parameter specifies the endpoint for the API request, such as "/users" or "/posts/1".
Note: Support to use "-" or "" to ignore this parameter.
Example usage:
client.SetURL("https", "example.com", "/api/v1", "/users")
func (*Client[T]) SetUserAgent ¶
SetUserAgent sets the value of the "User-Agent" header for the request. It takes a `ua` parameter, which is a string representing the value of the "User-Agent" header. This method allows specifying the user agent for the request. It returns a pointer to the `Client` instance to allow for method chaining.
Example usage:
client.SetUserAgent("MyApp/1.0")
func (*Client[T]) Then ¶
func (c *Client[T]) Then(cb CallbackOk[T]) *Client[T]
Then sets a callback function to be executed when the HTTP request is successful. The provided callback function cb is invoked only if no exception occurred during the request. The cb function is called with the result of the request as its argument. After executing the callback function, the client instance is returned.
func (*Client[T]) ToggleMode ¶
func (*Client[T]) UsePostHooks ¶
func (c *Client[T]) UsePostHooks(funcs ...afterResponse[T])
UsePostHooks response Interceptor Middleware
func (*Client[T]) UsePreHooks ¶
func (c *Client[T]) UsePreHooks(funcs ...beforeRequest[T])
UsePreHooks request interceptor middleware
type ClientFunc ¶
func Lambda ¶
func Lambda[T any](f func(*Client[T])) ClientFunc[T]
Lambda is a helper function that converts a function f into a ClientFunc[T]. It takes a function f as a parameter, which accepts a client instance and performs specific actions on it. The Lambda function wraps the provided function f and returns it as a ClientFunc[T]. The returned ClientFunc[T] can be used as an argument in the Optional method to apply the provided function to the client instance.
func WithDisabledRestMode
deprecated
func WithDisabledRestMode[T any]() ClientFunc[T]
Deprecated: WithDisabledRestMode Close the restful api mode, the request body will become the content of the T generic. Notes: This method is useful if your response body is not a standard restful response format data! Instead: Please use the ToggleMode method.
func WithFilterSlash
deprecated
added in
v0.1.4
func WithFilterSlash[T any](filterSlash bool) ClientFunc[T]
Deprecated: WithFilterSlash is a ClientFunc[T] function that sets the FilterSlash configuration of a client instance. It takes a boolean parameter filterSlash to enable or disable filtering of trailing slashes in URLs. When filterSlash is set to true, the client will remove any trailing slashes from the URLs it sends requests to. This can be useful in cases where the server treats URLs with and without trailing slashes differently. Note: that filtering slashes in URLs may affect the behavior of your requests, so use it carefully.
func WithIsDebug ¶
func WithIsDebug[T any](isDebug bool) ClientFunc[T]
WithIsDebug is a ClientFunc[T] function that sets the IsDebug configuration of a client instance. It takes a boolean value isDebug.
func WithModifySuccessCode
deprecated
func WithModifySuccessCode[T any](code int) ClientFunc[T]
Deprecated: WithModifySuccessCode sets the success return code for the client. The success code is used to identify successful responses. If not explicitly set, the default success code is 0.
func WithRegisterJsonLibrary ¶ added in v0.1.5
func WithRegisterJsonLibrary[T any](lib JSONLibrary) ClientFunc[T]
WithRegisterJsonLibrary is a ClientFunc[T] function that registers the json library for a client instance. You can choose the popular json parsing library independently. Note: Please implement the JSONLibrary interface definition yourself.
func WithSkipTLS ¶
func WithSkipTLS[T any](skipTLS bool) ClientFunc[T]
WithSkipTLS is a ClientFunc[T] function that sets the SkipTLS configuration of a client instance. It takes a boolean value skipTLS as a parameter and returns a ClientFunc[T]. When applied to a client instance using the Optional method, it sets the SkipTLS configuration of the client to the provided value.
func WithTimeout ¶
func WithTimeout[T any](timeout time.Duration) ClientFunc[T]
WithTimeout is a ClientFunc[T] function that configures the timeout duration for a client instance. It takes a time.Duration value timeout as a parameter and returns a ClientFunc[T]. When applied to a client instance using the Optional method, it configures the timeout duration based on the provided value. The timeout duration is capped to a minimum of TimeoutShort and a maximum of TimeoutLong.
func WithUseLogger ¶
func WithUseLogger[T any](enabled bool) ClientFunc[T]
WithUseLogger is a ClientFunc[T] function that configures the usage of a logger for a client instance. It takes a boolean value enabled as a parameter and returns a ClientFunc[T]. When applied to a client instance using the Optional method, it configures the usage of a logger based on the provided value. If enabled is true, it configures a custom log formatter for the client's logger. If enabled is false, it does not configure a logger for the client.
type ExecMethod ¶
type ExecMethod[T any] func(method string) *RESTFulResp[T]
type GoJSONLibrary ¶ added in v0.1.5
type GoJSONLibrary struct{}
GoJSONLibrary is an implementation of the popular tripartite library go-json.
func (GoJSONLibrary) Marshal ¶ added in v0.1.5
func (l GoJSONLibrary) Marshal(v interface{}) ([]byte, error)
func (GoJSONLibrary) Unmarshal ¶ added in v0.1.5
func (l GoJSONLibrary) Unmarshal(data []byte, v interface{}) error
type JSONLibrary ¶ added in v0.1.5
type JSONLibrary interface {
Marshal(v interface{}) ([]byte, error)
Unmarshal(data []byte, v interface{}) error
}
JSONLibrary Define the interface for serialization and deserialization of the json parsing library.
type NativeJSONLibrary ¶ added in v0.1.5
type NativeJSONLibrary struct{}
NativeJSONLibrary is the native implementation of encoding/json.
func (NativeJSONLibrary) Marshal ¶ added in v0.1.5
func (l NativeJSONLibrary) Marshal(v interface{}) ([]byte, error)
func (NativeJSONLibrary) Unmarshal ¶ added in v0.1.5
func (l NativeJSONLibrary) Unmarshal(data []byte, v interface{}) error
type RESTFulResp ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
http-style
command
|
|
|
requests-style
command
|
|
|
try-catch-style
command
|