Documentation
¶
Overview ¶
Package hotload is a database/sql driver that dynamically loads connection strings for other database drivers. To use it, import it like any other database driver and register the real database driver you want to use with hotload.
import ( // import the std lib sql package "database/sql" log "github.com/sirupsen/logrus" // this import registers hotload with the sql package "github.com/infobloxopen/hotload" // this import registers the fsnotify hotload strategy _ "github.com/infobloxopen/hotload/fsnotify" // this import registers the postgres driver with the sql package "github.com/lib/pq" ) func init() { // this function call registers the lib/pq postgres driver with hotload hotload.RegisterSQLDriver("postgres", pq.Driver{}) } func main() { db, err := sql.Open("hotload", "fsnotify://postgres/tmp/myconfig.txt") if err != nil { log.Fatalf("could not open db connection: %s", err) } db.Query("select 1") }
The above code: * registers the hotload driver with database/sql * registers the fsnotify strategy with hotload * registers the lib/pq postgres driver with database/sql * registers the lib/pq postgres driver with hotload
Then in the main() function the sql.Open call uses the hotload driver. The URL for the connection string specifies fsnotify in the scheme. This is the hotload strategy. The hostname in the URL specifies the real database driver. Finally the path and query parameters are left for the hotload strategy plugin to configure themselves. Below is an example of a lib/pq postgres connection string that would have been stored at /tmp/myconfig.txt
user=pqgotest dbname=pqgotest sslmode=verify-full
Index ¶
- Constants
- Variables
- func ContextWithExecLabels(ctx context.Context, labels map[string]string) context.Context
- func GetExecLabelsFromContext(ctx context.Context) map[string]string
- func GetLogger() logger.Logger
- func RegisterSQLDriver(name string, driver driver.Driver, options ...driverOption)
- func RegisterStrategy(name string, strategy Strategy)
- func SQLDrivers() []string
- func Strategies() []string
- func WithDriverOptions(options map[string]string) driverOption
- func WithLogger(l logger.Logger)
- type Strategy
Constants ¶
const ( GRPCMethodKey = "grpc_method" GRPCServiceKey = "grpc_service" StatementKey = "stmt" // either exec or query ExecStatement = "exec" QueryStatement = "query" )
Variables ¶
Functions ¶
func ContextWithExecLabels ¶ added in v1.3.0
func GetExecLabelsFromContext ¶ added in v1.3.0
func RegisterSQLDriver ¶
RegisterSQLDriver makes a database driver available by the provided name. If RegisterSQLDriver is called twice with the same name or if driver is nil, it panics.
func RegisterStrategy ¶
RegisterStrategy makes a database driver available by the provided name. If RegisterStrategy is called twice with the same name or if strategy is nil, it panics.
func SQLDrivers ¶
func SQLDrivers() []string
SQLDrivers returns a sorted list of the names of the registered drivers.
func Strategies ¶
func Strategies() []string
Strategies returns a sorted list of the names of the registered drivers.
func WithDriverOptions ¶ added in v1.2.1
WithDriverOptions allows you to specify query parameters to the underlying driver. The underlying driver must support URL style connection strings. The given options are appended to the connection string when a connection is opened.
func WithLogger ¶ added in v1.3.3
Types ¶
type Strategy ¶
type Strategy interface { // Watch returns back the contents of the resource as well as a channel // for subsequent updates (if the value has changed). If there is an error // getting the initial value, an error is returned. Watch(ctx context.Context, pth string, options url.Values) (value string, values <-chan string, err error) }
Strategy is the plugin interface for hotload.