mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-11-23 09:31:50 +08:00
fix(auth): keep config persistence off the request lock
This commit is contained in:
1 parent
04c8c54ff8
commit
ead58f0983
3 files changed
+206
-12
No files matched your search
+10
-2
@@ -1,6 +1,9 @@
|
||||
package db
|
||||
|
||||
import "database/sql"
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// Settings is a tiny key-value store for global app config the UI toggles at
|
||||
// runtime (e.g. traffic_capture). Missing keys fall back to caller defaults.
|
||||
@@ -19,7 +22,12 @@ func (d *DB) GetSetting(key string) (value string, ok bool, err error) {
|
||||
|
||||
// SetSetting upserts a setting value.
|
||||
func (d *DB) SetSetting(key, value string) error {
|
||||
_, err := d.Exec(`
|
||||
return d.SetSettingContext(context.Background(), key, value)
|
||||
}
|
||||
|
||||
// SetSettingContext upserts a setting and respects cancellation or a deadline.
|
||||
func (d *DB) SetSettingContext(ctx context.Context, key, value string) error {
|
||||
_, err := d.ExecContext(ctx, `
|
||||
INSERT INTO settings(key, value) VALUES ($1, $2)
|
||||
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, updated_at = now()`, key, value)
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user