mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Make default api listen address configurable, fix race conditions
This commit is contained in:
parent
bbf06b31ac
commit
60dbbe55e9
3 changed files with 21 additions and 11 deletions
|
@ -8,8 +8,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
listenAddressFlag string
|
||||
listenAddressConfig config.StringOption
|
||||
listenAddressFlag string
|
||||
listenAddressConfig config.StringOption
|
||||
defaultListenAddress string
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -37,13 +38,19 @@ func registerConfig() error {
|
|||
Description: "Define on what IP and port the API should listen on. Be careful, changing this may become a security issue.",
|
||||
ExpertiseLevel: config.ExpertiseLevelExpert,
|
||||
OptType: config.OptTypeString,
|
||||
DefaultValue: "127.0.0.1:18",
|
||||
DefaultValue: defaultListenAddress,
|
||||
ValidationRegex: "^([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5}|\\[[:0-9A-Fa-f]+\\]:[0-9]{1,5})$",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
listenAddressConfig = config.GetAsString("api/listenAddress", "127.0.0.1:18")
|
||||
listenAddressConfig = config.GetAsString("api/listenAddress", defaultListenAddress)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetDefaultAPIListenAddress(address string) {
|
||||
if defaultListenAddress == "" {
|
||||
defaultListenAddress = address
|
||||
}
|
||||
}
|
||||
|
|
|
@ -367,7 +367,10 @@ func (api *DatabaseAPI) processSub(opID []byte, sub *database.Subscription) {
|
|||
continue
|
||||
}
|
||||
// TODO: use upd, new and delete msgTypes
|
||||
if r.Meta().IsDeleted() {
|
||||
r.Lock()
|
||||
isDeleted := r.Meta().IsDeleted()
|
||||
r.Unlock()
|
||||
if isDeleted {
|
||||
api.send(opID, dbMsgTypeDel, r.Key(), nil)
|
||||
} else {
|
||||
api.send(opID, dbMsgTypeUpd, r.Key(), data)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func init() {
|
||||
modules.Register("config", prep, start, stop, "database")
|
||||
modules.Register("config", prep, start, nil, "database")
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
|
@ -19,14 +19,14 @@ func prep() error {
|
|||
func start() error {
|
||||
configFilePath = path.Join(database.GetDatabaseRoot(), "config.json")
|
||||
|
||||
err := loadConfig()
|
||||
err := registerAsDatabase()
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
return registerAsDatabase()
|
||||
}
|
||||
|
||||
func stop() error {
|
||||
err = loadConfig()
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue