Documentation
¶
Overview ¶
Package soforo provides a generic interface around drivers for various connection types. It can be used for databases, storage and other connection types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver[R Repository] interface { // Open returns a new Repository or an error. It is the caller's // responsibility to call Close on Repository when the Repository is no // longer needed. The provider argument is used to provide the driver with // additional context. Some drivers need other services to be available in // the provider struct. The driver must verify that the provided // instance is of the expected type and return an error if it is not. Open(url *url.URL, provider interface{}) (R, error) }
Driver is the interface that must be implemented by a driver implementation. This interface is generic and should be extended by the consuming package to specify the type of Repository that the driver provides. In most cases, the Driver interface in the consuming packages won't need extra methods.
type Drivers ¶
type Drivers[D Driver[R], R Repository] struct { // contains filtered or unexported fields }
Drivers is a collection of drivers that can be used to open a repository. The drivers are stored in a map and can be registered using the Register method. The Open method can be used to open a repository using the URL. The URL scheme is used to determine which driver to use. The Drivers collection is safe for concurrent use, because it uses a mutex to synchronize access to the map.
func NewDrivers ¶
func NewDrivers[D Driver[R], R Repository](name string) *Drivers[D, R]
NewDrivers returns a new Drivers collection.
func (*Drivers[D, R]) Driver ¶
Driver returns the driver with the provided name. If the driver is not registered, an error is returned. It uses the URL scheme to determine which driver to use.
func (*Drivers[D, R]) DriverByName ¶
DriverByName returns the driver with the provided name. If the driver is not registered, an error is returned.
func (*Drivers[D, R]) Drivers ¶
Drivers returns a sorted list of the names of the registered drivers.
func (*Drivers[D, R]) Open ¶
Open opens a Repository from a driver using the URL. It is the caller's responsibility to call Close on Repository when the Repository is no longer needed. Open uses the URL scheme to determine which driver to use. If the driver is unknown, Open returns an error. The provider argument is used to provide the driver with additional context. The driver must verify that the provided instance is of the expected type and return an error if it is not.
type Repository ¶
type Repository interface {
Close() error
}
Repository the value that eventually ends up in the application. This interface should be extended by the consuming package to include the methods that the repository provides.