mirror of
https://github.com/tiennm99/keepalive.git
synced 2026-10-11 03:13:31 +00:00
feat(config): support multi-service yaml config
This commit is contained in:
1 parent
655db8dcbf
commit
f3a23ee91e
19 files changed
+709
-268
No files matched your search
+12
-7
@@ -9,20 +9,26 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
Registry["mysql"] = func() (Adapter, error) { return &mysqlAdapter{}, nil }
|
||||
Registry["mysql"] = func(cfg Config) (Adapter, error) {
|
||||
dsn, err := cfg.Required("dsn")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &mysqlAdapter{
|
||||
dsn: dsn,
|
||||
key: cfg.Optional("counter_key", "counter"),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
type mysqlAdapter struct {
|
||||
db *sql.DB
|
||||
dsn string
|
||||
key string
|
||||
}
|
||||
|
||||
func (a *mysqlAdapter) Connect(ctx context.Context) error {
|
||||
dsn, err := envOrFail("KEEPALIVE_MYSQL_DSN")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
db, err := sql.Open("mysql", dsn)
|
||||
db, err := sql.Open("mysql", a.dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -30,7 +36,6 @@ func (a *mysqlAdapter) Connect(ctx context.Context) error {
|
||||
db.SetMaxOpenConns(10)
|
||||
db.SetMaxIdleConns(10)
|
||||
a.db = db
|
||||
a.key = envOr("KEEPALIVE_COUNTER_KEY", "counter")
|
||||
return a.db.PingContext(ctx)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user