*: fix golangci-lint warnings
This commit is contained in:
@@ -375,7 +375,7 @@ func (clients *clientsContainer) FindAutoClient(ip string) (ClientHost, bool) {
|
||||
// Check if Client object's fields are correct
|
||||
func (clients *clientsContainer) check(c *Client) error {
|
||||
if len(c.Name) == 0 {
|
||||
return fmt.Errorf("Invalid Name")
|
||||
return fmt.Errorf("invalid Name")
|
||||
}
|
||||
|
||||
if len(c.IDs) == 0 {
|
||||
@@ -399,12 +399,12 @@ func (clients *clientsContainer) check(c *Client) error {
|
||||
continue
|
||||
}
|
||||
|
||||
return fmt.Errorf("Invalid ID: %s", id)
|
||||
return fmt.Errorf("invalid ID: %s", id)
|
||||
}
|
||||
|
||||
for _, t := range c.Tags {
|
||||
if !clients.tagKnown(t) {
|
||||
return fmt.Errorf("Invalid tag: %s", t)
|
||||
return fmt.Errorf("invalid tag: %s", t)
|
||||
}
|
||||
}
|
||||
sort.Strings(c.Tags)
|
||||
@@ -412,7 +412,7 @@ func (clients *clientsContainer) check(c *Client) error {
|
||||
if len(c.Upstreams) != 0 {
|
||||
err := dnsforward.ValidateUpstreams(c.Upstreams)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Invalid upstream servers: %s", err)
|
||||
return fmt.Errorf("invalid upstream servers: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ func (clients *clientsContainer) Add(c Client) (bool, error) {
|
||||
for _, id := range c.IDs {
|
||||
c2, ok := clients.idIndex[id]
|
||||
if ok {
|
||||
return false, fmt.Errorf("Another client uses the same ID (%s): %s", id, c2.Name)
|
||||
return false, fmt.Errorf("another client uses the same ID (%s): %s", id, c2.Name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,14 +501,14 @@ func (clients *clientsContainer) Update(name string, c Client) error {
|
||||
|
||||
old, ok := clients.list[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("Client not found")
|
||||
return fmt.Errorf("client not found")
|
||||
}
|
||||
|
||||
// check Name index
|
||||
if old.Name != c.Name {
|
||||
_, ok = clients.list[c.Name]
|
||||
if ok {
|
||||
return fmt.Errorf("Client already exists")
|
||||
return fmt.Errorf("client already exists")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ func (clients *clientsContainer) Update(name string, c Client) error {
|
||||
for _, id := range c.IDs {
|
||||
c2, ok := clients.idIndex[id]
|
||||
if ok && c2 != old {
|
||||
return fmt.Errorf("Another client uses the same ID (%s): %s", id, c2.Name)
|
||||
return fmt.Errorf("another client uses the same ID (%s): %s", id, c2.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,9 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
|
||||
for i := 0; i != 3; i++ {
|
||||
log.Tracef("Downloading data from %s", versionCheckURL)
|
||||
resp, err = Context.client.Get(versionCheckURL)
|
||||
if resp != nil && resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
if err != nil && strings.HasSuffix(err.Error(), "i/o timeout") {
|
||||
// This case may happen while we're restarting DNS server
|
||||
// https://github.com/AdguardTeam/AdGuardHome/issues/934
|
||||
@@ -123,9 +126,6 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
|
||||
httpError(w, http.StatusBadGateway, "Couldn't get version check json from %s: %T %s\n", versionCheckURL, err, err)
|
||||
return
|
||||
}
|
||||
if resp != nil && resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
// read the body entirely
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
@@ -187,11 +187,11 @@ func getUpdateInfo(jsonData []byte) (*updateInfo, error) {
|
||||
u.pkgURL = versionJSON[fmt.Sprintf("download_%s_%s", runtime.GOOS, runtime.GOARCH)].(string)
|
||||
u.newVer = versionJSON["version"].(string)
|
||||
if len(u.pkgURL) == 0 || len(u.newVer) == 0 {
|
||||
return nil, fmt.Errorf("Invalid JSON")
|
||||
return nil, fmt.Errorf("invalid JSON")
|
||||
}
|
||||
|
||||
if u.newVer == versionString {
|
||||
return nil, fmt.Errorf("No need to update")
|
||||
return nil, fmt.Errorf("no need to update")
|
||||
}
|
||||
|
||||
u.updateDir = filepath.Join(workDir, fmt.Sprintf("agh-update-%s", u.newVer))
|
||||
@@ -199,7 +199,7 @@ func getUpdateInfo(jsonData []byte) (*updateInfo, error) {
|
||||
|
||||
_, pkgFileName := filepath.Split(u.pkgURL)
|
||||
if len(pkgFileName) == 0 {
|
||||
return nil, fmt.Errorf("Invalid JSON")
|
||||
return nil, fmt.Errorf("invalid JSON")
|
||||
}
|
||||
u.pkgName = filepath.Join(u.updateDir, pkgFileName)
|
||||
|
||||
@@ -215,7 +215,7 @@ func getUpdateInfo(jsonData []byte) (*updateInfo, error) {
|
||||
}
|
||||
u.curBinName = filepath.Join(workDir, binName)
|
||||
if !util.FileExists(u.curBinName) {
|
||||
return nil, fmt.Errorf("Executable file %s doesn't exist", u.curBinName)
|
||||
return nil, fmt.Errorf("executable file %s doesn't exist", u.curBinName)
|
||||
}
|
||||
u.bkpBinName = filepath.Join(u.backupDir, binName)
|
||||
u.newBinName = filepath.Join(u.updateDir, "AdGuardHome", binName)
|
||||
@@ -432,7 +432,7 @@ func doUpdate(u *updateInfo) error {
|
||||
return fmt.Errorf("targzFileUnpack() failed: %s", err)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("Unknown package extension")
|
||||
return fmt.Errorf("unknown package extension")
|
||||
}
|
||||
|
||||
log.Tracef("Checking configuration")
|
||||
@@ -517,9 +517,7 @@ func finishUpdate(u *updateInfo) {
|
||||
log.Fatalf("exec.Command() failed: %s", err)
|
||||
}
|
||||
os.Exit(0)
|
||||
|
||||
} else {
|
||||
|
||||
log.Info("Restarting: %v", os.Args)
|
||||
err := syscall.Exec(u.curBinName, os.Args, os.Environ())
|
||||
if err != nil {
|
||||
|
||||
@@ -37,7 +37,7 @@ func initDNSServer() error {
|
||||
}
|
||||
Context.stats, err = stats.New(statsConf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Couldn't initialize statistics module")
|
||||
return fmt.Errorf("couldn't initialize statistics module")
|
||||
}
|
||||
conf := querylog.Config{
|
||||
Enabled: config.DNS.QueryLogEnabled,
|
||||
|
||||
@@ -290,7 +290,7 @@ func (f *Filtering) periodicallyRefreshFilters() {
|
||||
func (f *Filtering) refreshFilters(flags int, important bool) (int, error) {
|
||||
set := atomic.CompareAndSwapUint32(&f.refreshStatus, 0, 1)
|
||||
if !important && !set {
|
||||
return 0, fmt.Errorf("Filters update procedure is already running")
|
||||
return 0, fmt.Errorf("filters update procedure is already running")
|
||||
}
|
||||
|
||||
f.refreshLock.Lock()
|
||||
@@ -550,13 +550,13 @@ func (f *Filtering) updateIntl(filter *filter) (bool, error) {
|
||||
|
||||
if firstChunkLen == len(firstChunk) || err == io.EOF {
|
||||
if !isPrintableText(firstChunk) {
|
||||
return false, fmt.Errorf("Data contains non-printable characters")
|
||||
return false, fmt.Errorf("data contains non-printable characters")
|
||||
}
|
||||
|
||||
s := strings.ToLower(string(firstChunk))
|
||||
if strings.Index(s, "<html") >= 0 ||
|
||||
strings.Index(s, "<!doctype") >= 0 {
|
||||
return false, fmt.Errorf("Data is HTML, not plain text")
|
||||
return false, fmt.Errorf("data is HTML, not plain text")
|
||||
}
|
||||
|
||||
htmlTest = false
|
||||
|
||||
@@ -306,6 +306,8 @@ func verifyCertChain(data *tlsConfigStatus, certChain string, serverName string)
|
||||
if decoded.Type == "CERTIFICATE" {
|
||||
certs = append(certs, decoded)
|
||||
} else {
|
||||
// ignore "this result of append is never used" warning
|
||||
// nolint
|
||||
skippedBytes = append(skippedBytes, decoded.Type)
|
||||
}
|
||||
}
|
||||
@@ -387,6 +389,8 @@ func validatePkey(data *tlsConfigStatus, pkey string) error {
|
||||
key = decoded
|
||||
break
|
||||
} else {
|
||||
// ignore "this result of append is never used"
|
||||
// nolint
|
||||
skippedBytes = append(skippedBytes, decoded.Type)
|
||||
}
|
||||
}
|
||||
|
||||
76
home/web.go
76
home/web.go
@@ -81,11 +81,11 @@ func WebCheckPortAvailable(port int) bool {
|
||||
}
|
||||
|
||||
// TLSConfigChanged - called when TLS configuration has changed
|
||||
func (w *Web) TLSConfigChanged(tlsConf tlsConfigSettings) {
|
||||
func (web *Web) TLSConfigChanged(tlsConf tlsConfigSettings) {
|
||||
log.Debug("Web: applying new TLS configuration")
|
||||
w.conf.PortHTTPS = tlsConf.PortHTTPS
|
||||
w.forceHTTPS = (tlsConf.ForceHTTPS && tlsConf.Enabled && tlsConf.PortHTTPS != 0)
|
||||
w.portHTTPS = tlsConf.PortHTTPS
|
||||
web.conf.PortHTTPS = tlsConf.PortHTTPS
|
||||
web.forceHTTPS = (tlsConf.ForceHTTPS && tlsConf.Enabled && tlsConf.PortHTTPS != 0)
|
||||
web.portHTTPS = tlsConf.PortHTTPS
|
||||
|
||||
enabled := tlsConf.Enabled &&
|
||||
tlsConf.PortHTTPS != 0 &&
|
||||
@@ -100,31 +100,31 @@ func (w *Web) TLSConfigChanged(tlsConf tlsConfigSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
w.httpsServer.cond.L.Lock()
|
||||
if w.httpsServer.server != nil {
|
||||
w.httpsServer.server.Shutdown(context.TODO())
|
||||
web.httpsServer.cond.L.Lock()
|
||||
if web.httpsServer.server != nil {
|
||||
_ = web.httpsServer.server.Shutdown(context.TODO())
|
||||
}
|
||||
w.httpsServer.enabled = enabled
|
||||
w.httpsServer.cert = cert
|
||||
w.httpsServer.cond.Broadcast()
|
||||
w.httpsServer.cond.L.Unlock()
|
||||
web.httpsServer.enabled = enabled
|
||||
web.httpsServer.cert = cert
|
||||
web.httpsServer.cond.Broadcast()
|
||||
web.httpsServer.cond.L.Unlock()
|
||||
}
|
||||
|
||||
// Start - start serving HTTP requests
|
||||
func (w *Web) Start() {
|
||||
func (web *Web) Start() {
|
||||
// for https, we have a separate goroutine loop
|
||||
go w.httpServerLoop()
|
||||
go web.httpServerLoop()
|
||||
|
||||
// this loop is used as an ability to change listening host and/or port
|
||||
for !w.httpsServer.shutdown {
|
||||
for !web.httpsServer.shutdown {
|
||||
printHTTPAddresses("http")
|
||||
|
||||
// we need to have new instance, because after Shutdown() the Server is not usable
|
||||
address := net.JoinHostPort(w.conf.BindHost, strconv.Itoa(w.conf.BindPort))
|
||||
w.httpServer = &http.Server{
|
||||
address := net.JoinHostPort(web.conf.BindHost, strconv.Itoa(web.conf.BindPort))
|
||||
web.httpServer = &http.Server{
|
||||
Addr: address,
|
||||
}
|
||||
err := w.httpServer.ListenAndServe()
|
||||
err := web.httpServer.ListenAndServe()
|
||||
if err != http.ErrServerClosed {
|
||||
cleanupAlways()
|
||||
log.Fatal(err)
|
||||
@@ -134,46 +134,46 @@ func (w *Web) Start() {
|
||||
}
|
||||
|
||||
// Close - stop HTTP server, possibly waiting for all active connections to be closed
|
||||
func (w *Web) Close() {
|
||||
func (web *Web) Close() {
|
||||
log.Info("Stopping HTTP server...")
|
||||
w.httpsServer.cond.L.Lock()
|
||||
w.httpsServer.shutdown = true
|
||||
w.httpsServer.cond.L.Unlock()
|
||||
if w.httpsServer.server != nil {
|
||||
_ = w.httpsServer.server.Shutdown(context.TODO())
|
||||
web.httpsServer.cond.L.Lock()
|
||||
web.httpsServer.shutdown = true
|
||||
web.httpsServer.cond.L.Unlock()
|
||||
if web.httpsServer.server != nil {
|
||||
_ = web.httpsServer.server.Shutdown(context.TODO())
|
||||
}
|
||||
if w.httpServer != nil {
|
||||
_ = w.httpServer.Shutdown(context.TODO())
|
||||
if web.httpServer != nil {
|
||||
_ = web.httpServer.Shutdown(context.TODO())
|
||||
}
|
||||
|
||||
log.Info("Stopped HTTP server")
|
||||
}
|
||||
|
||||
func (w *Web) httpServerLoop() {
|
||||
func (web *Web) httpServerLoop() {
|
||||
for {
|
||||
w.httpsServer.cond.L.Lock()
|
||||
if w.httpsServer.shutdown {
|
||||
w.httpsServer.cond.L.Unlock()
|
||||
web.httpsServer.cond.L.Lock()
|
||||
if web.httpsServer.shutdown {
|
||||
web.httpsServer.cond.L.Unlock()
|
||||
break
|
||||
}
|
||||
|
||||
// this mechanism doesn't let us through until all conditions are met
|
||||
for !w.httpsServer.enabled { // sleep until necessary data is supplied
|
||||
w.httpsServer.cond.Wait()
|
||||
if w.httpsServer.shutdown {
|
||||
w.httpsServer.cond.L.Unlock()
|
||||
for !web.httpsServer.enabled { // sleep until necessary data is supplied
|
||||
web.httpsServer.cond.Wait()
|
||||
if web.httpsServer.shutdown {
|
||||
web.httpsServer.cond.L.Unlock()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
w.httpsServer.cond.L.Unlock()
|
||||
web.httpsServer.cond.L.Unlock()
|
||||
|
||||
// prepare HTTPS server
|
||||
address := net.JoinHostPort(w.conf.BindHost, strconv.Itoa(w.conf.PortHTTPS))
|
||||
w.httpsServer.server = &http.Server{
|
||||
address := net.JoinHostPort(web.conf.BindHost, strconv.Itoa(web.conf.PortHTTPS))
|
||||
web.httpsServer.server = &http.Server{
|
||||
Addr: address,
|
||||
TLSConfig: &tls.Config{
|
||||
Certificates: []tls.Certificate{w.httpsServer.cert},
|
||||
Certificates: []tls.Certificate{web.httpsServer.cert},
|
||||
MinVersion: tls.VersionTLS12,
|
||||
RootCAs: Context.tlsRoots,
|
||||
CipherSuites: Context.tlsCiphers,
|
||||
@@ -181,7 +181,7 @@ func (w *Web) httpServerLoop() {
|
||||
}
|
||||
|
||||
printHTTPAddresses("https")
|
||||
err := w.httpsServer.server.ListenAndServeTLS("", "")
|
||||
err := web.httpsServer.server.ListenAndServeTLS("", "")
|
||||
if err != http.ErrServerClosed {
|
||||
cleanupAlways()
|
||||
log.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user