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 Middlewares(middlewares_ []middleware.Middleware) Option[RestConf, *RestConf]
- func Timeout(timeout_ time.Duration) Option[RestConf, *RestConf]
- func Use(middleware middleware.Middleware) Option[RestConf, *RestConf]
- 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_ time.Duration)
- func (r RestConf) ShootNew()
- func (r *RestConf) Timeout() time.Duration
- func (r *RestConf) With(opts ...Option[RestConf, *RestConf]) *RestConf
- type RestConfGetter
- type RestConfSetter
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 Middlewares ¶
func Middlewares(middlewares_ []middleware.Middleware) Option[RestConf, *RestConf]
Middlewares is a configuration for the filed Middlewares
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 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 {
Middlewares []middleware.Middleware
// contains filtered or unexported fields
}
RestConf holds configuration parameters for initializing a RestClient.
func NewRestConf ¶
func NewRestConf(baseURL string, timeout time.Duration, 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