Documentation
¶
Index ¶
- func IsEnum[T constraints.EnumShooter[T], TV constraints.Integer](value TV) bool
- func NewRest[T RestClient[T]](opts ...Option[RestConf, *RestConf]) T
- func NewWith[T any, PT constraints.NewShooter[T]](opts ...Option[T, PT]) *T
- func ParseEnum[T constraints.EnumShooter[T]](str string) (T, error)
- func Register[T RestClient[T]](ctor func(RestConf) T)
- func TryParseEnum[T constraints.EnumShooter[T]](str string, v *T) bool
- type Option
- func BaseURL(baseURL_ string) Option[RestConf, *RestConf]
- func DefaultHeaders(defaultHeaders_ map[string]string) Option[RestConf, *RestConf]
- func EnableLogging(enableLogging_ bool) Option[RestConf, *RestConf]
- func Timeout(timeout_ string) Option[RestConf, *RestConf]
- func Use(middleware middleware.Middleware) Option[RestConf, *RestConf]
- type Response
- func (r *Response) Body() []byte
- func (r *Response) Close() error
- func (r *Response) Cookies() []*http.Cookie
- func (r *Response) Header() http.Header
- func (r *Response) IsError() bool
- func (r *Response) IsSuccess() bool
- func (r *Response) Proto() string
- func (r *Response) RawBody() io.ReadCloser
- func (r *Response) Size() int64
- func (r *Response) Status() string
- func (r *Response) StatusCode() int
- func (r *Response) String() string
- type RestClient
- type RestConf
- func (r *RestConf) BaseURL() string
- func (r *RestConf) BuildMiddleware() http.RoundTripper
- func (r *RestConf) DefaultHeaders() map[string]string
- func (r *RestConf) EnableLogging() bool
- func (r *RestConf) SetBaseURL(baseURL_ string)
- func (r *RestConf) SetDefaultHeaders(defaultHeaders_ map[string]string)
- func (r *RestConf) SetEnableLogging(enableLogging_ bool)
- func (r *RestConf) SetTimeout(timeout_ string)
- func (r RestConf) ShootNew()
- func (r *RestConf) Timeout() string
- func (r *RestConf) With(opts ...Option[RestConf, *RestConf]) *RestConf
- type RestConfGetter
- type RestConfSetter
- type StreamResponse
- func (r *StreamResponse) Body() io.ReadCloser
- func (r *StreamResponse) Close() error
- func (r *StreamResponse) Cookies() []*http.Cookie
- func (r *StreamResponse) Header() http.Header
- func (r *StreamResponse) IsError() bool
- func (r *StreamResponse) IsSuccess() bool
- func (r *StreamResponse) Proto() string
- func (r *StreamResponse) Status() string
- func (r *StreamResponse) StatusCode() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEnum ¶
func IsEnum[T constraints.EnumShooter[T], TV constraints.Integer](value TV) bool
IsEnum checks whether a given integer value is a valid enum value of type T. Useful for validating raw input before casting or using it as an enum.
func NewRest ¶
func NewRest[T RestClient[T]](opts ...Option[RestConf, *RestConf]) T
NewRest creates a new instance of type T that implements the RestClient interface.
func NewWith ¶
func NewWith[T any, PT constraints.NewShooter[T]](opts ...Option[T, PT]) *T
NewWith creates a new instance of type T using the functional options pattern. It first initializes the instance with default values via SetDefault, then applies each provided Option in order. This pattern promotes clean, declarative construction of configurable types.
func ParseEnum ¶
func ParseEnum[T constraints.EnumShooter[T]](str string) (T, error)
ParseEnum attempts to convert a string into its corresponding enum value. It uses the ValueMap() provided by the enum type to look up the value. Returns an error if the string does not match any known enum value.
func Register ¶
func Register[T RestClient[T]](ctor func(RestConf) T)
Register associates a constructor function with a specific RestClient implementation. The constructor must accept a RestConf and return a concrete type that satisfies RestClient.
func TryParseEnum ¶
func TryParseEnum[T constraints.EnumShooter[T]](str string, v *T) bool
TryParseEnum is a safe variant of ParseEnum. It attempts to parse the string into an enum value and stores the result in v. Returns true if successful, false otherwise. Does not return an error.
Types ¶
type Option ¶
type Option[T any, PT constraints.NewShooter[T]] func(*T)
Option defines a functional option for configuring an instance of type T. PT is a pointer type that satisfies DefaultSetter[T], allowing default setup.
func DefaultHeaders ¶
DefaultHeaders is a configuration for the filed defaultHeaders
func EnableLogging ¶
EnableLogging is a configuration for the filed enableLogging
func Use ¶
func Use(middleware middleware.Middleware) Option[RestConf, *RestConf]
Use returns an Option function that applies the given middleware to a RestConf instance.
type Response ¶ added in v0.8.1
Response wraps the response returned by net/http.
Body contains a cached copy of the response payload. RawResponse.Body has already been consumed and closed by the generated client.
func NewResponse ¶ added in v0.8.1
NewResponse constructs a Response for generated clients.
func (*Response) Body ¶ added in v0.8.1
Body returns the response payload cached by the generated client.
func (*Response) Close ¶ added in v0.8.1
Close closes the underlying response body. Generated clients have normally closed it already.
func (*Response) IsSuccess ¶ added in v0.8.1
IsSuccess reports whether the status code is in the 2xx range.
func (*Response) RawBody ¶ added in v0.8.1
func (r *Response) RawBody() io.ReadCloser
RawBody returns the consumed and closed underlying response body. Use StreamResponse for responses that must be read incrementally.
func (*Response) Status ¶ added in v0.8.1
Status returns the HTTP status text, for example "200 OK".
func (*Response) StatusCode ¶ added in v0.8.1
StatusCode returns the HTTP status code.
type RestClient ¶
type RestClient[T any] interface { ConfigHTTPClient(config func(client *http.Client)) T ShootRest() }
RestClient defines the interface for REST-capable clients.
type RestConf ¶
type RestConf struct {
// contains filtered or unexported fields
}
RestConf holds configuration parameters for initializing a RestClient.
func NewRestConf ¶
func NewRestConf(baseUrl string, timeout string, enableLogging bool, defaultHeaders map[string]string) *RestConf
NewRestConf constructs a new instance of type RestConf
func (*RestConf) BuildMiddleware ¶
func (r *RestConf) BuildMiddleware() http.RoundTripper
BuildMiddleware constructs the middleware chain by wrapping the default HTTP transport.
func (*RestConf) DefaultHeaders ¶
DefaultHeaders gets the value of field defaultHeaders
func (*RestConf) EnableLogging ¶
EnableLogging gets the value of field enableLogging
func (*RestConf) SetBaseURL ¶
SetBaseURL sets the value of field baseURL
func (*RestConf) SetDefaultHeaders ¶
SetDefaultHeaders sets the value of field defaultHeaders
func (*RestConf) SetEnableLogging ¶
SetEnableLogging sets the value of field enableLogging
func (*RestConf) SetTimeout ¶
SetTimeout sets the value of field timeout
func (RestConf) ShootNew ¶
func (r RestConf) ShootNew()
ShootNew exists solely to fulfill the NewShooter interface contract
type RestConfGetter ¶
type RestConfGetter interface {
BaseURL() string
Timeout() string
EnableLogging() bool
DefaultHeaders() map[string]string
}
RestConfGetter is read-only interface for RestConf type
type RestConfSetter ¶
type RestConfSetter interface {
SetBaseURL(string)
SetTimeout(string)
SetEnableLogging(bool)
SetDefaultHeaders(map[string]string)
}
RestConfSetter is write-only interface for RestConf type
type StreamResponse ¶ added in v0.8.1
StreamResponse wraps an HTTP response whose body has not been consumed. The caller must close it after reading, including when the request returns a non-nil error together with a StreamResponse.
func NewStreamResponse ¶ added in v0.8.1
func NewStreamResponse(rawResponse *http.Response) *StreamResponse
NewStreamResponse constructs a StreamResponse for generated clients.
func (*StreamResponse) Body ¶ added in v0.8.1
func (r *StreamResponse) Body() io.ReadCloser
Body returns the underlying response stream. The caller must close it.
func (*StreamResponse) Close ¶ added in v0.8.1
func (r *StreamResponse) Close() error
Close closes the underlying response stream.
func (*StreamResponse) Cookies ¶ added in v0.8.1
func (r *StreamResponse) Cookies() []*http.Cookie
Cookies returns the cookies included in the response.
func (*StreamResponse) Header ¶ added in v0.8.1
func (r *StreamResponse) Header() http.Header
Header returns the response headers.
func (*StreamResponse) IsError ¶ added in v0.8.1
func (r *StreamResponse) IsError() bool
IsError reports whether the status code is 4xx or 5xx.
func (*StreamResponse) IsSuccess ¶ added in v0.8.1
func (r *StreamResponse) IsSuccess() bool
IsSuccess reports whether the status code is in the 2xx range.
func (*StreamResponse) Proto ¶ added in v0.8.1
func (r *StreamResponse) Proto() string
Proto returns the HTTP protocol used for the response.
func (*StreamResponse) Status ¶ added in v0.8.1
func (r *StreamResponse) Status() string
Status returns the HTTP status text, for example "200 OK".
func (*StreamResponse) StatusCode ¶ added in v0.8.1
func (r *StreamResponse) StatusCode() int
StatusCode returns the HTTP status code.