Pull request 2314: AGDNS-2374-slog-home-webapi
Squashed commit of the following:
commit 7c457d92b5a2d931c22388d37ad30f10dc0ecd89
Merge: bcd3d29df 11dfc7a3e
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Dec 5 18:24:08 2024 +0300
Merge branch 'master' into AGDNS-2374-slog-home-webapi
commit bcd3d29dfde4af7d223e2d2468dd01635f799bb9
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Dec 5 18:24:01 2024 +0300
all: imp code
commit f3af1bf3dd476733d0286eeea9f6dd5ebbdb4950
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Dec 4 18:33:35 2024 +0300
home: imp code
commit 035477513f433346c7bf3215083c317466b4b734
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Tue Dec 3 19:01:55 2024 +0300
home: imp code
commit 5368d8de50d266b438a4909d81b5fec76b5ca65c
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Tue Dec 3 17:25:37 2024 +0300
home: imp code
commit fce1bf475f33f6fe45252e2276ea8ebf2a82a8b2
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Mon Dec 2 18:20:31 2024 +0300
home: slog webapi
This commit is contained in:
@@ -167,13 +167,13 @@ func setupContext(opts options) (err error) {
|
||||
if err != nil {
|
||||
log.Error("parsing configuration file: %s", err)
|
||||
|
||||
os.Exit(1)
|
||||
os.Exit(osutil.ExitCodeFailure)
|
||||
}
|
||||
|
||||
if opts.checkConfig {
|
||||
log.Info("configuration file is ok")
|
||||
|
||||
os.Exit(0)
|
||||
os.Exit(osutil.ExitCodeSuccess)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -522,18 +522,20 @@ func isUpdateEnabled(ctx context.Context, l *slog.Logger, opts *options, customU
|
||||
}
|
||||
}
|
||||
|
||||
// initWeb initializes the web module.
|
||||
// initWeb initializes the web module. upd and baseLogger must not be nil.
|
||||
func initWeb(
|
||||
ctx context.Context,
|
||||
opts options,
|
||||
clientBuildFS fs.FS,
|
||||
upd *updater.Updater,
|
||||
l *slog.Logger,
|
||||
baseLogger *slog.Logger,
|
||||
customURL bool,
|
||||
) (web *webAPI, err error) {
|
||||
logger := baseLogger.With(slogutil.KeyPrefix, "webapi")
|
||||
|
||||
var clientFS fs.FS
|
||||
if opts.localFrontend {
|
||||
log.Info("warning: using local frontend files")
|
||||
logger.WarnContext(ctx, "using local frontend files")
|
||||
|
||||
clientFS = os.DirFS("build/static")
|
||||
} else {
|
||||
@@ -543,10 +545,12 @@ func initWeb(
|
||||
}
|
||||
}
|
||||
|
||||
disableUpdate := !isUpdateEnabled(ctx, l, &opts, customURL)
|
||||
disableUpdate := !isUpdateEnabled(ctx, baseLogger, &opts, customURL)
|
||||
|
||||
webConf := &webConfig{
|
||||
updater: upd,
|
||||
updater: upd,
|
||||
logger: logger,
|
||||
baseLogger: baseLogger,
|
||||
|
||||
clientFS: clientFS,
|
||||
|
||||
@@ -562,7 +566,7 @@ func initWeb(
|
||||
serveHTTP3: config.DNS.ServeHTTP3,
|
||||
}
|
||||
|
||||
web = newWebAPI(webConf, l)
|
||||
web = newWebAPI(ctx, webConf)
|
||||
if web == nil {
|
||||
return nil, errors.Error("can not initialize web")
|
||||
}
|
||||
@@ -640,7 +644,7 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
|
||||
fatalOnError(err)
|
||||
|
||||
if config.HTTPConfig.Pprof.Enabled {
|
||||
startPprof(config.HTTPConfig.Pprof.Port)
|
||||
startPprof(slogLogger, config.HTTPConfig.Pprof.Port)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -692,7 +696,7 @@ func run(opts options, clientBuildFS fs.FS, done chan struct{}) {
|
||||
checkPermissions(ctx, slogLogger, Context.workDir, confPath, dataDir, statsDir, querylogDir)
|
||||
}
|
||||
|
||||
Context.web.start()
|
||||
Context.web.start(ctx)
|
||||
|
||||
// Wait for other goroutines to complete their job.
|
||||
<-done
|
||||
@@ -803,15 +807,15 @@ func (c *configuration) anonymizer() (ipmut *aghnet.IPMut) {
|
||||
return aghnet.NewIPMut(anonFunc)
|
||||
}
|
||||
|
||||
// startMods initializes and starts the DNS server after installation. l must
|
||||
// not be nil.
|
||||
func startMods(l *slog.Logger) (err error) {
|
||||
// startMods initializes and starts the DNS server after installation.
|
||||
// baseLogger must not be nil.
|
||||
func startMods(baseLogger *slog.Logger) (err error) {
|
||||
statsDir, querylogDir, err := checkStatsAndQuerylogDirs(&Context, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = initDNS(l, statsDir, querylogDir)
|
||||
err = initDNS(baseLogger, statsDir, querylogDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -984,7 +988,7 @@ func loadCmdLineOpts() (opts options) {
|
||||
exitWithError()
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
os.Exit(osutil.ExitCodeSuccess)
|
||||
}
|
||||
|
||||
return opts
|
||||
|
||||
Reference in New Issue
Block a user