Pull request 1897: nextapi-write-conf

Squashed commit of the following:

commit 72f25ffe73d6b8216b01e590fba66fb5f6944113
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Jun 28 21:29:04 2023 +0300

    next: add conf writing, validation
This commit is contained in:
Ainar Garipov
2023-06-29 14:34:06 +03:00
parent 2069eddf98
commit d4a4bda645
10 changed files with 232 additions and 37 deletions

View File

@@ -19,8 +19,6 @@ import (
func Main(frontend fs.FS) {
start := time.Now()
// Initial Configuration
cmdName := os.Args[0]
opts, err := parseOptions(cmdName, os.Args[1:])
exitCode, needExit := processOptions(opts, cmdName, err)
@@ -39,9 +37,7 @@ func Main(frontend fs.FS) {
check(err)
}
// Web Service
confMgr, err := configmgr.New(opts.confFile, frontend, start)
confMgr, err := newConfigMgr(opts.confFile, frontend, start)
check(err)
web := confMgr.Web()
@@ -73,6 +69,15 @@ func ctxWithDefaultTimeout() (ctx context.Context, cancel context.CancelFunc) {
return context.WithTimeout(context.Background(), defaultTimeout)
}
// newConfigMgr returns a new configuration manager using defaultTimeout as the
// context timeout.
func newConfigMgr(confFile string, frontend fs.FS, start time.Time) (m *configmgr.Manager, err error) {
ctx, cancel := ctxWithDefaultTimeout()
defer cancel()
return configmgr.New(ctx, confFile, frontend, start)
}
// check is a simple error-checking helper. It must only be used within Main.
func check(err error) {
if err != nil {