mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-30 02:28:16 +03:00
84a2991ac2
Squashed commit of the following: commit 71d8936bddcf2d2b293015d3091df72aa1333270 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jul 20 18:48:08 2023 +0300 next/websvc: fix pprof disabling commit 30cc75d1eb89f7422555c18ad474324ab55eb13b Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jul 20 18:30:29 2023 +0300 all: upd golibs; add pprof to next
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package websvc
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"io/fs"
|
|
"net/netip"
|
|
"time"
|
|
)
|
|
|
|
// Config is the AdGuard Home web service configuration structure.
|
|
type Config struct {
|
|
// Pprof is the configuration for the pprof debug API. It must not be nil.
|
|
Pprof *PprofConfig
|
|
|
|
// ConfigManager is used to show information about services as well as
|
|
// dynamically reconfigure them.
|
|
ConfigManager ConfigManager
|
|
|
|
// Frontend is the filesystem with the frontend and other statically
|
|
// compiled files.
|
|
Frontend fs.FS
|
|
|
|
// TLS is the optional TLS configuration. If TLS is not nil,
|
|
// SecureAddresses must not be empty.
|
|
TLS *tls.Config
|
|
|
|
// Start is the time of start of AdGuard Home.
|
|
Start time.Time
|
|
|
|
// OverrideAddress is the initial or override address for the HTTP API. If
|
|
// set, it is used instead of [Addresses] and [SecureAddresses].
|
|
OverrideAddress netip.AddrPort
|
|
|
|
// Addresses are the addresses on which to serve the plain HTTP API.
|
|
Addresses []netip.AddrPort
|
|
|
|
// SecureAddresses are the addresses on which to serve the HTTPS API. If
|
|
// SecureAddresses is not empty, TLS must not be nil.
|
|
SecureAddresses []netip.AddrPort
|
|
|
|
// Timeout is the timeout for all server operations.
|
|
Timeout time.Duration
|
|
|
|
// ForceHTTPS tells if all requests to Addresses should be redirected to a
|
|
// secure address instead.
|
|
//
|
|
// TODO(a.garipov): Use; define rules, which address to redirect to.
|
|
ForceHTTPS bool
|
|
}
|
|
|
|
// PprofConfig is the configuration for the pprof debug API.
|
|
type PprofConfig struct {
|
|
Port uint16 `yaml:"port"`
|
|
Enabled bool `yaml:"enabled"`
|
|
}
|
|
|
|
// Config returns the current configuration of the web service. Config must not
|
|
// be called simultaneously with Start. If svc was initialized with ":0"
|
|
// addresses, addrs will not return the actual bound ports until Start is
|
|
// finished.
|
|
func (svc *Service) Config() (c *Config) {
|
|
c = &Config{
|
|
Pprof: &PprofConfig{
|
|
Port: svc.pprofPort,
|
|
Enabled: svc.pprof != nil,
|
|
},
|
|
ConfigManager: svc.confMgr,
|
|
TLS: svc.tls,
|
|
// Leave Addresses and SecureAddresses empty and get the actual
|
|
// addresses that include the :0 ones later.
|
|
Start: svc.start,
|
|
Timeout: svc.timeout,
|
|
ForceHTTPS: svc.forceHTTPS,
|
|
}
|
|
|
|
c.Addresses, c.SecureAddresses = svc.addrs()
|
|
|
|
return c
|
|
}
|