mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Add RequiresRestart attribute to config option
This commit is contained in:
parent
456b53ae72
commit
05bead1890
2 changed files with 101 additions and 100 deletions
|
@ -5,25 +5,25 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/database"
|
||||
"github.com/safing/portbase/database/storage"
|
||||
"github.com/safing/portbase/database/record"
|
||||
"github.com/safing/portbase/database/query"
|
||||
"github.com/safing/portbase/database/iterator"
|
||||
"github.com/safing/portbase/database/query"
|
||||
"github.com/safing/portbase/database/record"
|
||||
"github.com/safing/portbase/database/storage"
|
||||
"github.com/safing/portbase/log"
|
||||
)
|
||||
|
||||
var (
|
||||
dbController *database.Controller
|
||||
)
|
||||
|
||||
// ConfigStorageInterface provices a storage.Interface to the configuration manager.
|
||||
type ConfigStorageInterface struct {
|
||||
// StorageInterface provices a storage.Interface to the configuration manager.
|
||||
type StorageInterface struct {
|
||||
storage.InjectBase
|
||||
}
|
||||
|
||||
// Get returns a database record.
|
||||
func (s *ConfigStorageInterface) Get(key string) (record.Record, error) {
|
||||
func (s *StorageInterface) Get(key string) (record.Record, error) {
|
||||
optionsLock.Lock()
|
||||
defer optionsLock.Unlock()
|
||||
|
||||
|
@ -36,7 +36,7 @@ func (s *ConfigStorageInterface) Get(key string) (record.Record, error) {
|
|||
}
|
||||
|
||||
// Put stores a record in the database.
|
||||
func (s *ConfigStorageInterface) Put(r record.Record) error {
|
||||
func (s *StorageInterface) Put(r record.Record) error {
|
||||
if r.Meta().Deleted > 0 {
|
||||
return setConfigOption(r.DatabaseKey(), nil, false)
|
||||
}
|
||||
|
@ -60,13 +60,13 @@ func (s *ConfigStorageInterface) Put(r record.Record) error {
|
|||
|
||||
var value interface{}
|
||||
switch option.OptType {
|
||||
case OptTypeString :
|
||||
case OptTypeString:
|
||||
value, ok = acc.GetString("Value")
|
||||
case OptTypeStringArray :
|
||||
case OptTypeStringArray:
|
||||
value, ok = acc.GetStringArray("Value")
|
||||
case OptTypeInt :
|
||||
case OptTypeInt:
|
||||
value, ok = acc.GetInt("Value")
|
||||
case OptTypeBool :
|
||||
case OptTypeBool:
|
||||
value, ok = acc.GetBool("Value")
|
||||
}
|
||||
if !ok {
|
||||
|
@ -81,12 +81,12 @@ func (s *ConfigStorageInterface) Put(r record.Record) error {
|
|||
}
|
||||
|
||||
// Delete deletes a record from the database.
|
||||
func (s *ConfigStorageInterface) Delete(key string) error {
|
||||
func (s *StorageInterface) Delete(key string) error {
|
||||
return setConfigOption(key, nil, false)
|
||||
}
|
||||
|
||||
// Query returns a an iterator for the supplied query.
|
||||
func (s *ConfigStorageInterface) Query(q *query.Query, local, internal bool) (*iterator.Iterator, error) {
|
||||
func (s *StorageInterface) Query(q *query.Query, local, internal bool) (*iterator.Iterator, error) {
|
||||
|
||||
optionsLock.Lock()
|
||||
defer optionsLock.Unlock()
|
||||
|
@ -104,7 +104,7 @@ func (s *ConfigStorageInterface) Query(q *query.Query, local, internal bool) (*i
|
|||
return it, nil
|
||||
}
|
||||
|
||||
func (s *ConfigStorageInterface) processQuery(q *query.Query, it *iterator.Iterator, opts []*Option) {
|
||||
func (s *StorageInterface) processQuery(q *query.Query, it *iterator.Iterator, opts []*Option) {
|
||||
|
||||
sort.Sort(sortableOptions(opts))
|
||||
|
||||
|
@ -121,7 +121,7 @@ func (s *ConfigStorageInterface) processQuery(q *query.Query, it *iterator.Itera
|
|||
}
|
||||
|
||||
// ReadOnly returns whether the database is read only.
|
||||
func (s *ConfigStorageInterface) ReadOnly() bool {
|
||||
func (s *StorageInterface) ReadOnly() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ func registerAsDatabase() error {
|
|||
return err
|
||||
}
|
||||
|
||||
controller, err := database.InjectDatabase("config", &ConfigStorageInterface{})
|
||||
controller, err := database.InjectDatabase("config", &StorageInterface{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/tidwall/sjson"
|
||||
|
||||
|
@ -47,6 +47,7 @@ type Option struct {
|
|||
DefaultValue interface{}
|
||||
ExternalOptType string
|
||||
ValidationRegex string
|
||||
RequiresRestart bool
|
||||
compiledRegex *regexp.Regexp
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue