mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-05-01 05:31:38 +03:00
Pull request 2314: AGDNS-2374-slog-home-webapi
Squashed commit of the following: commit7c457d92b5
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 commitbcd3d29dfd
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Dec 5 18:24:01 2024 +0300 all: imp code commitf3af1bf3dd
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Dec 4 18:33:35 2024 +0300 home: imp code commit035477513f
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Dec 3 19:01:55 2024 +0300 home: imp code commit5368d8de50
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Dec 3 17:25:37 2024 +0300 home: imp code commitfce1bf475f
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Dec 2 18:20:31 2024 +0300 home: slog webapi
This commit is contained in:
parent
11dfc7a3e8
commit
dab608292a
7 changed files with 175 additions and 109 deletions
internal/home
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue