Documentation
¶
Overview ¶
Package openurl provides helpers for URLMux and URLOpeners in portable APIs.
Index ¶
- func DSNToURL(driver string, dsn string, prefix string) *url.URL
- func GetMemPoolShardExpr() string
- func NewPoolWatcher[W watch.Watcher](p *Pool[W]) watch.Watcher
- func RegisterTemplateInjector(injector TemplateInjector)
- func RegisterTplFunc(name string, fn any)
- func RegisterURLTemplate(scheme string, opener TemplateOpener, asDefault ...bool)
- func SetMemPoolShardExpr(v string)
- func URLToDSN(u *url.URL) (driver string, dsn string, prefix string)
- type MustOpener
- type Opener
- type Pool
- func MemPool[T any](ctx context.Context, opener Opener[T], opt ...PoolOption[T]) (*Pool[T], error)
- func MustMemPool[T any](ctx context.Context, opener MustOpener[T], opt ...PoolOption[T]) *Pool[T]
- func OpenPool[T any](ctx context.Context, uu []string, opener Opener[T], opt ...PoolOption[T]) (*Pool[T], error)
- func (m *Pool[T]) Close(ctx context.Context, iterate ...func(key string, res T) error) error
- func (m *Pool[T]) Del(ctx context.Context, resolutionData ...map[string]interface{}) (bool, error)
- func (m *Pool[T]) Get(ctx context.Context, resolutionData ...map[string]interface{}) (T, error)
- func (m *Pool[T]) Iterate(ctx context.Context, it func(key string, res T) error) error
- func (m *Pool[T]) On(action PoolAction, f func(k string, t T)) Stopper
- type PoolAction
- type PoolOption
- type PoolOptions
- type Provider
- type Resolver
- type ResourceClosable
- type SchemeMap
- func (m *SchemeMap) FromString(typ, urlstr string) (interface{}, *url.URL, error)
- func (m *SchemeMap) FromStringNoParse(typ, urlstr string) (interface{}, error)
- func (m *SchemeMap) FromURL(typ string, u *url.URL) (interface{}, error)
- func (m *SchemeMap) Register(api, typ, scheme string, value interface{})
- func (m *SchemeMap) Schemes() []string
- func (m *SchemeMap) ValidScheme(scheme string) bool
- type Stopper
- type StringTemplate
- type Template
- type TemplateInjector
- type TemplateOpener
- type URLMux
- type URLOpener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMemPoolShardExpr ¶
func GetMemPoolShardExpr() string
func RegisterTemplateInjector ¶
func RegisterTemplateInjector(injector TemplateInjector)
RegisterTemplateInjector appends a TemplateInjector to extract info from context before passing to templates
func RegisterTplFunc ¶
RegisterTplFunc appends an arbitrary executable func
func RegisterURLTemplate ¶
func RegisterURLTemplate(scheme string, opener TemplateOpener, asDefault ...bool)
RegisterURLTemplate registers a template type by scheme. Default go-template is supported by default
func SetMemPoolShardExpr ¶
func SetMemPoolShardExpr(v string)
Types ¶
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
func MustMemPool ¶
func MustMemPool[T any](ctx context.Context, opener MustOpener[T], opt ...PoolOption[T]) *Pool[T]
MustMemPool opens a pool that differentiate based on memPoolShardExpr, and does not trigger any errors
func OpenPool ¶
func OpenPool[T any](ctx context.Context, uu []string, opener Opener[T], opt ...PoolOption[T]) (*Pool[T], error)
OpenPool creates a pool of resources that are resolved at Get() time. If PoolOption is passed, it will monitor idle resources and close them regulary to free memory Maybe PoolOptions could also be passed by the URL
type PoolOption ¶
type PoolOption[T any] func(*PoolOptions[T])
func WithCleanTicker ¶
func WithCleanTicker[T any](duration time.Duration) PoolOption[T]
func WithMaxIdleTime ¶
func WithMaxIdleTime[T any](duration time.Duration) PoolOption[T]
func WithOpener ¶
func WithOpener[T any](opener Opener[T]) PoolOption[T]
func WithProvider ¶
func WithProvider[T any](provider Provider[T]) PoolOption[T]
type PoolOptions ¶
type ResourceClosable ¶
type SchemeMap ¶
type SchemeMap struct {
// contains filtered or unexported fields
}
SchemeMap maps URL schemes to values. The zero value is an empty map, ready for use.
func (*SchemeMap) FromString ¶
FromString parses urlstr as an URL and looks up the value for the URL's scheme.
func (*SchemeMap) FromStringNoParse ¶
FromStringNoParse parses urlstr as an URL and looks up the value for the URL's scheme.
func (*SchemeMap) Register ¶
Register registers scheme for value; subsequent calls to FromString or FromURL with scheme will return value. api is the portable API name (e.g., "blob"); the same value should always be passed. It should be in all lowercase. typ is the portable type (e.g., "Bucket"). Register panics if scheme has already been registered.
func (*SchemeMap) ValidScheme ¶
ValidScheme returns true if scheme has been registered.
type StringTemplate ¶
type Template ¶
type Template interface { StringTemplate ResolveURL(ctx context.Context, optionalData ...map[string]interface{}) (*url.URL, error) }
func URLTemplate ¶
URLTemplate initialize a Template based on rawURL for later resolution
type TemplateOpener ¶
type URLMux ¶
type URLMux[T any] struct { // contains filtered or unexported fields }
URLMux is a URL opener multiplexer. It matches the scheme of the URLs against a set of registered schemes and calls the opener that matches the URL's scheme. See https://gocloud.dev/concepts/urls/ for more information.
The zero value is a multiplexer with no registered schemes.
func NewURLMux ¶
Driver packages can use this to register their TopicURLOpener and/or SubscriptionURLOpener on the mux.
func (*URLMux[T]) Open ¶
OpenStore calls OpenURL with the URL parsed from urlstr. OpenStore is safe to call from multiple goroutines.
func (*URLMux[T]) Register ¶
Register registers the opener with the given scheme. If an opener already exists for the scheme, Register panics.
func (*URLMux[T]) ValidScheme ¶
ValidScheme returns true if scheme has been registered.