*: fix golangci-lint warnings

This commit is contained in:
Andrey Meshkov 2020-04-05 18:34:43 +03:00
parent d5b826e12f
commit 7b8588afa4
12 changed files with 86 additions and 82 deletions

View File

@ -65,3 +65,5 @@ issues:
- Error return value of ..*.Shutdown. - Error return value of ..*.Shutdown.
# goconst # goconst
- string .forcesafesearch.google.com. has 3 occurrences - string .forcesafesearch.google.com. has 3 occurrences
# gosec: Subprocess launched with function call as argument or cmd arguments
- G204

View File

@ -227,7 +227,7 @@ func (s *Server) Start() error {
// TODO: don't close if interface and addresses are the same // TODO: don't close if interface and addresses are the same
if s.conn != nil { if s.conn != nil {
s.closeConn() _ = s.closeConn()
} }
iface, err := net.InterfaceByName(s.conf.InterfaceName) iface, err := net.InterfaceByName(s.conf.InterfaceName)
@ -251,7 +251,7 @@ func (s *Server) Start() error {
if err != nil && !s.stopping { if err != nil && !s.stopping {
log.Printf("dhcp4.Serve() returned with error: %s", err) log.Printf("dhcp4.Serve() returned with error: %s", err)
} }
c.Close() // in case Serve() exits for other reason than listening socket closure _ = c.Close() // in case Serve() exits for other reason than listening socket closure
s.running = false s.running = false
s.cond.Signal() s.cond.Signal()
}() }()
@ -609,10 +609,10 @@ func (s *Server) handleDecline(p dhcp4.Packet, options dhcp4.Options) dhcp4.Pack
// AddStaticLease adds a static lease (thread-safe) // AddStaticLease adds a static lease (thread-safe)
func (s *Server) AddStaticLease(l Lease) error { func (s *Server) AddStaticLease(l Lease) error {
if len(l.IP) != 4 { if len(l.IP) != 4 {
return fmt.Errorf("Invalid IP") return fmt.Errorf("invalid IP")
} }
if len(l.HWAddr) != 6 { if len(l.HWAddr) != 6 {
return fmt.Errorf("Invalid MAC") return fmt.Errorf("invalid MAC")
} }
l.Expiry = time.Unix(leaseExpireStatic, 0) l.Expiry = time.Unix(leaseExpireStatic, 0)
@ -637,9 +637,9 @@ func (s *Server) AddStaticLease(l Lease) error {
func (s *Server) rmDynamicLeaseWithIP(ip net.IP) error { func (s *Server) rmDynamicLeaseWithIP(ip net.IP) error {
var newLeases []*Lease var newLeases []*Lease
for _, lease := range s.leases { for _, lease := range s.leases {
if bytes.Equal(lease.IP.To4(), ip) { if net.IP.Equal(lease.IP.To4(), ip) {
if lease.Expiry.Unix() == leaseExpireStatic { if lease.Expiry.Unix() == leaseExpireStatic {
return fmt.Errorf("Static lease with the same IP already exists") return fmt.Errorf("static lease with the same IP already exists")
} }
continue continue
} }
@ -654,7 +654,7 @@ func (s *Server) rmDynamicLeaseWithIP(ip net.IP) error {
func (s *Server) rmLease(l Lease) error { func (s *Server) rmLease(l Lease) error {
var newLeases []*Lease var newLeases []*Lease
for _, lease := range s.leases { for _, lease := range s.leases {
if bytes.Equal(lease.IP.To4(), l.IP) { if net.IP.Equal(lease.IP.To4(), l.IP) {
if !bytes.Equal(lease.HWAddr, l.HWAddr) || if !bytes.Equal(lease.HWAddr, l.HWAddr) ||
lease.Hostname != l.Hostname { lease.Hostname != l.Hostname {
return fmt.Errorf("Lease not found") return fmt.Errorf("Lease not found")
@ -671,17 +671,17 @@ func (s *Server) rmLease(l Lease) error {
// RemoveStaticLease removes a static lease (thread-safe) // RemoveStaticLease removes a static lease (thread-safe)
func (s *Server) RemoveStaticLease(l Lease) error { func (s *Server) RemoveStaticLease(l Lease) error {
if len(l.IP) != 4 { if len(l.IP) != 4 {
return fmt.Errorf("Invalid IP") return fmt.Errorf("invalid IP")
} }
if len(l.HWAddr) != 6 { if len(l.HWAddr) != 6 {
return fmt.Errorf("Invalid MAC") return fmt.Errorf("invalid MAC")
} }
s.leasesLock.Lock() s.leasesLock.Lock()
if s.findReservedHWaddr(l.IP) == nil { if s.findReservedHWaddr(l.IP) == nil {
s.leasesLock.Unlock() s.leasesLock.Unlock()
return fmt.Errorf("Lease not found") return fmt.Errorf("lease not found")
} }
err := s.rmLease(l) err := s.rmLease(l)

View File

@ -33,7 +33,7 @@ func HasStaticIP(ifaceName string) (bool, error) {
return hasStaticIPDarwin(ifaceName) return hasStaticIPDarwin(ifaceName)
} }
return false, fmt.Errorf("Cannot check if IP is static: not supported on %s", runtime.GOOS) return false, fmt.Errorf("cannot check if IP is static: not supported on %s", runtime.GOOS)
} }
// Set a static IP for the specified network interface // Set a static IP for the specified network interface
@ -46,7 +46,7 @@ func SetStaticIP(ifaceName string) error {
return setStaticIPDarwin(ifaceName) return setStaticIPDarwin(ifaceName)
} }
return fmt.Errorf("Cannot set static IP on %s", runtime.GOOS) return fmt.Errorf("cannot set static IP on %s", runtime.GOOS)
} }
// for dhcpcd.conf // for dhcpcd.conf
@ -114,7 +114,7 @@ func getGatewayIP(ifaceName string) string {
func setStaticIPDhcpdConf(ifaceName string) error { func setStaticIPDhcpdConf(ifaceName string) error {
ip := util.GetSubnet(ifaceName) ip := util.GetSubnet(ifaceName)
if len(ip) == 0 { if len(ip) == 0 {
return errors.New("Can't get IP address") return errors.New("can't get IP address")
} }
ip4, _, err := net.ParseCIDR(ip) ip4, _, err := net.ParseCIDR(ip)
@ -198,7 +198,7 @@ func setStaticIPDarwin(ifaceName string) error {
return err return err
} }
if code != 0 { if code != 0 {
return fmt.Errorf("Failed to set DNS servers, code=%d", code) return fmt.Errorf("failed to set DNS servers, code=%d", code)
} }
// Actually configures hardware port to have static IP // Actually configures hardware port to have static IP
@ -208,7 +208,7 @@ func setStaticIPDarwin(ifaceName string) error {
return err return err
} }
if code != 0 { if code != 0 {
return fmt.Errorf("Failed to set DNS servers, code=%d", code) return fmt.Errorf("failed to set DNS servers, code=%d", code)
} }
return nil return nil
@ -220,7 +220,7 @@ func getCurrentHardwarePortInfo(ifaceName string) (hardwarePortInfo, error) {
m := getNetworkSetupHardwareReports() m := getNetworkSetupHardwareReports()
hardwarePort, ok := m[ifaceName] hardwarePort, ok := m[ifaceName]
if !ok { if !ok {
return hardwarePortInfo{}, fmt.Errorf("Could not find hardware port for %s", ifaceName) return hardwarePortInfo{}, fmt.Errorf("could not find hardware port for %s", ifaceName)
} }
return getHardwarePortInfo(hardwarePort) return getHardwarePortInfo(hardwarePort)
@ -274,7 +274,7 @@ func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) {
match := re.FindStringSubmatch(out) match := re.FindStringSubmatch(out)
if len(match) == 0 { if len(match) == 0 {
return h, errors.New("Could not find hardware port info") return h, errors.New("could not find hardware port info")
} }
h.name = hardwarePort h.name = hardwarePort
@ -300,7 +300,7 @@ func getEtcResolvConfServers() ([]string, error) {
matches := re.FindAllStringSubmatch(string(body), -1) matches := re.FindAllStringSubmatch(string(body), -1)
if len(matches) == 0 { if len(matches) == 0 {
return nil, errors.New("Found no DNS servers in /etc/resolv.conf") return nil, errors.New("found no DNS servers in /etc/resolv.conf")
} }
addrs := make([]string, 0) addrs := make([]string, 0)

View File

@ -80,7 +80,7 @@ func main() {
panic(err) panic(err)
} }
log.Printf("Now serving DHCP") log.Printf("Now serving DHCP")
signalChannel := make(chan os.Signal) signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM) signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM)
<-signalChannel <-signalChannel

View File

@ -407,7 +407,7 @@ func matchDNSName(dnsNames []string, sni string) bool {
func (s *Server) onGetCertificate(ch *tls.ClientHelloInfo) (*tls.Certificate, error) { func (s *Server) onGetCertificate(ch *tls.ClientHelloInfo) (*tls.Certificate, error) {
if s.conf.StrictSNICheck && !matchDNSName(s.conf.dnsNames, ch.ServerName) { if s.conf.StrictSNICheck && !matchDNSName(s.conf.dnsNames, ch.ServerName) {
log.Info("DNS: TLS: unknown SNI in Client Hello: %s", ch.ServerName) log.Info("DNS: TLS: unknown SNI in Client Hello: %s", ch.ServerName)
return nil, fmt.Errorf("Invalid SNI") return nil, fmt.Errorf("invalid SNI")
} }
return &s.conf.cert, nil return &s.conf.cert, nil
} }

View File

@ -375,7 +375,7 @@ func (clients *clientsContainer) FindAutoClient(ip string) (ClientHost, bool) {
// Check if Client object's fields are correct // Check if Client object's fields are correct
func (clients *clientsContainer) check(c *Client) error { func (clients *clientsContainer) check(c *Client) error {
if len(c.Name) == 0 { if len(c.Name) == 0 {
return fmt.Errorf("Invalid Name") return fmt.Errorf("invalid Name")
} }
if len(c.IDs) == 0 { if len(c.IDs) == 0 {
@ -399,12 +399,12 @@ func (clients *clientsContainer) check(c *Client) error {
continue continue
} }
return fmt.Errorf("Invalid ID: %s", id) return fmt.Errorf("invalid ID: %s", id)
} }
for _, t := range c.Tags { for _, t := range c.Tags {
if !clients.tagKnown(t) { if !clients.tagKnown(t) {
return fmt.Errorf("Invalid tag: %s", t) return fmt.Errorf("invalid tag: %s", t)
} }
} }
sort.Strings(c.Tags) sort.Strings(c.Tags)
@ -412,7 +412,7 @@ func (clients *clientsContainer) check(c *Client) error {
if len(c.Upstreams) != 0 { if len(c.Upstreams) != 0 {
err := dnsforward.ValidateUpstreams(c.Upstreams) err := dnsforward.ValidateUpstreams(c.Upstreams)
if err != nil { 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 { for _, id := range c.IDs {
c2, ok := clients.idIndex[id] c2, ok := clients.idIndex[id]
if ok { 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] old, ok := clients.list[name]
if !ok { if !ok {
return fmt.Errorf("Client not found") return fmt.Errorf("client not found")
} }
// check Name index // check Name index
if old.Name != c.Name { if old.Name != c.Name {
_, ok = clients.list[c.Name] _, ok = clients.list[c.Name]
if ok { 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 { for _, id := range c.IDs {
c2, ok := clients.idIndex[id] c2, ok := clients.idIndex[id]
if ok && c2 != old { 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)
} }
} }

View File

@ -112,6 +112,9 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
for i := 0; i != 3; i++ { for i := 0; i != 3; i++ {
log.Tracef("Downloading data from %s", versionCheckURL) log.Tracef("Downloading data from %s", versionCheckURL)
resp, err = Context.client.Get(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") { if err != nil && strings.HasSuffix(err.Error(), "i/o timeout") {
// This case may happen while we're restarting DNS server // This case may happen while we're restarting DNS server
// https://github.com/AdguardTeam/AdGuardHome/issues/934 // 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) httpError(w, http.StatusBadGateway, "Couldn't get version check json from %s: %T %s\n", versionCheckURL, err, err)
return return
} }
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
// read the body entirely // read the body entirely
body, err := ioutil.ReadAll(resp.Body) 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.pkgURL = versionJSON[fmt.Sprintf("download_%s_%s", runtime.GOOS, runtime.GOARCH)].(string)
u.newVer = versionJSON["version"].(string) u.newVer = versionJSON["version"].(string)
if len(u.pkgURL) == 0 || len(u.newVer) == 0 { 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 { 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)) 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) _, pkgFileName := filepath.Split(u.pkgURL)
if len(pkgFileName) == 0 { if len(pkgFileName) == 0 {
return nil, fmt.Errorf("Invalid JSON") return nil, fmt.Errorf("invalid JSON")
} }
u.pkgName = filepath.Join(u.updateDir, pkgFileName) u.pkgName = filepath.Join(u.updateDir, pkgFileName)
@ -215,7 +215,7 @@ func getUpdateInfo(jsonData []byte) (*updateInfo, error) {
} }
u.curBinName = filepath.Join(workDir, binName) u.curBinName = filepath.Join(workDir, binName)
if !util.FileExists(u.curBinName) { 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.bkpBinName = filepath.Join(u.backupDir, binName)
u.newBinName = filepath.Join(u.updateDir, "AdGuardHome", 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) return fmt.Errorf("targzFileUnpack() failed: %s", err)
} }
} else { } else {
return fmt.Errorf("Unknown package extension") return fmt.Errorf("unknown package extension")
} }
log.Tracef("Checking configuration") log.Tracef("Checking configuration")
@ -517,9 +517,7 @@ func finishUpdate(u *updateInfo) {
log.Fatalf("exec.Command() failed: %s", err) log.Fatalf("exec.Command() failed: %s", err)
} }
os.Exit(0) os.Exit(0)
} else { } else {
log.Info("Restarting: %v", os.Args) log.Info("Restarting: %v", os.Args)
err := syscall.Exec(u.curBinName, os.Args, os.Environ()) err := syscall.Exec(u.curBinName, os.Args, os.Environ())
if err != nil { if err != nil {

View File

@ -37,7 +37,7 @@ func initDNSServer() error {
} }
Context.stats, err = stats.New(statsConf) Context.stats, err = stats.New(statsConf)
if err != nil { if err != nil {
return fmt.Errorf("Couldn't initialize statistics module") return fmt.Errorf("couldn't initialize statistics module")
} }
conf := querylog.Config{ conf := querylog.Config{
Enabled: config.DNS.QueryLogEnabled, Enabled: config.DNS.QueryLogEnabled,

View File

@ -290,7 +290,7 @@ func (f *Filtering) periodicallyRefreshFilters() {
func (f *Filtering) refreshFilters(flags int, important bool) (int, error) { func (f *Filtering) refreshFilters(flags int, important bool) (int, error) {
set := atomic.CompareAndSwapUint32(&f.refreshStatus, 0, 1) set := atomic.CompareAndSwapUint32(&f.refreshStatus, 0, 1)
if !important && !set { 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() f.refreshLock.Lock()
@ -550,13 +550,13 @@ func (f *Filtering) updateIntl(filter *filter) (bool, error) {
if firstChunkLen == len(firstChunk) || err == io.EOF { if firstChunkLen == len(firstChunk) || err == io.EOF {
if !isPrintableText(firstChunk) { 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)) s := strings.ToLower(string(firstChunk))
if strings.Index(s, "<html") >= 0 || if strings.Index(s, "<html") >= 0 ||
strings.Index(s, "<!doctype") >= 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 htmlTest = false

View File

@ -306,6 +306,8 @@ func verifyCertChain(data *tlsConfigStatus, certChain string, serverName string)
if decoded.Type == "CERTIFICATE" { if decoded.Type == "CERTIFICATE" {
certs = append(certs, decoded) certs = append(certs, decoded)
} else { } else {
// ignore "this result of append is never used" warning
// nolint
skippedBytes = append(skippedBytes, decoded.Type) skippedBytes = append(skippedBytes, decoded.Type)
} }
} }
@ -387,6 +389,8 @@ func validatePkey(data *tlsConfigStatus, pkey string) error {
key = decoded key = decoded
break break
} else { } else {
// ignore "this result of append is never used"
// nolint
skippedBytes = append(skippedBytes, decoded.Type) skippedBytes = append(skippedBytes, decoded.Type)
} }
} }

View File

@ -81,11 +81,11 @@ func WebCheckPortAvailable(port int) bool {
} }
// TLSConfigChanged - called when TLS configuration has changed // 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") log.Debug("Web: applying new TLS configuration")
w.conf.PortHTTPS = tlsConf.PortHTTPS web.conf.PortHTTPS = tlsConf.PortHTTPS
w.forceHTTPS = (tlsConf.ForceHTTPS && tlsConf.Enabled && tlsConf.PortHTTPS != 0) web.forceHTTPS = (tlsConf.ForceHTTPS && tlsConf.Enabled && tlsConf.PortHTTPS != 0)
w.portHTTPS = tlsConf.PortHTTPS web.portHTTPS = tlsConf.PortHTTPS
enabled := tlsConf.Enabled && enabled := tlsConf.Enabled &&
tlsConf.PortHTTPS != 0 && tlsConf.PortHTTPS != 0 &&
@ -100,31 +100,31 @@ func (w *Web) TLSConfigChanged(tlsConf tlsConfigSettings) {
} }
} }
w.httpsServer.cond.L.Lock() web.httpsServer.cond.L.Lock()
if w.httpsServer.server != nil { if web.httpsServer.server != nil {
w.httpsServer.server.Shutdown(context.TODO()) _ = web.httpsServer.server.Shutdown(context.TODO())
} }
w.httpsServer.enabled = enabled web.httpsServer.enabled = enabled
w.httpsServer.cert = cert web.httpsServer.cert = cert
w.httpsServer.cond.Broadcast() web.httpsServer.cond.Broadcast()
w.httpsServer.cond.L.Unlock() web.httpsServer.cond.L.Unlock()
} }
// Start - start serving HTTP requests // Start - start serving HTTP requests
func (w *Web) Start() { func (web *Web) Start() {
// for https, we have a separate goroutine loop // 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 // this loop is used as an ability to change listening host and/or port
for !w.httpsServer.shutdown { for !web.httpsServer.shutdown {
printHTTPAddresses("http") printHTTPAddresses("http")
// we need to have new instance, because after Shutdown() the Server is not usable // 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)) address := net.JoinHostPort(web.conf.BindHost, strconv.Itoa(web.conf.BindPort))
w.httpServer = &http.Server{ web.httpServer = &http.Server{
Addr: address, Addr: address,
} }
err := w.httpServer.ListenAndServe() err := web.httpServer.ListenAndServe()
if err != http.ErrServerClosed { if err != http.ErrServerClosed {
cleanupAlways() cleanupAlways()
log.Fatal(err) log.Fatal(err)
@ -134,46 +134,46 @@ func (w *Web) Start() {
} }
// Close - stop HTTP server, possibly waiting for all active connections to be closed // 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...") log.Info("Stopping HTTP server...")
w.httpsServer.cond.L.Lock() web.httpsServer.cond.L.Lock()
w.httpsServer.shutdown = true web.httpsServer.shutdown = true
w.httpsServer.cond.L.Unlock() web.httpsServer.cond.L.Unlock()
if w.httpsServer.server != nil { if web.httpsServer.server != nil {
_ = w.httpsServer.server.Shutdown(context.TODO()) _ = web.httpsServer.server.Shutdown(context.TODO())
} }
if w.httpServer != nil { if web.httpServer != nil {
_ = w.httpServer.Shutdown(context.TODO()) _ = web.httpServer.Shutdown(context.TODO())
} }
log.Info("Stopped HTTP server") log.Info("Stopped HTTP server")
} }
func (w *Web) httpServerLoop() { func (web *Web) httpServerLoop() {
for { for {
w.httpsServer.cond.L.Lock() web.httpsServer.cond.L.Lock()
if w.httpsServer.shutdown { if web.httpsServer.shutdown {
w.httpsServer.cond.L.Unlock() web.httpsServer.cond.L.Unlock()
break break
} }
// this mechanism doesn't let us through until all conditions are met // this mechanism doesn't let us through until all conditions are met
for !w.httpsServer.enabled { // sleep until necessary data is supplied for !web.httpsServer.enabled { // sleep until necessary data is supplied
w.httpsServer.cond.Wait() web.httpsServer.cond.Wait()
if w.httpsServer.shutdown { if web.httpsServer.shutdown {
w.httpsServer.cond.L.Unlock() web.httpsServer.cond.L.Unlock()
return return
} }
} }
w.httpsServer.cond.L.Unlock() web.httpsServer.cond.L.Unlock()
// prepare HTTPS server // prepare HTTPS server
address := net.JoinHostPort(w.conf.BindHost, strconv.Itoa(w.conf.PortHTTPS)) address := net.JoinHostPort(web.conf.BindHost, strconv.Itoa(web.conf.PortHTTPS))
w.httpsServer.server = &http.Server{ web.httpsServer.server = &http.Server{
Addr: address, Addr: address,
TLSConfig: &tls.Config{ TLSConfig: &tls.Config{
Certificates: []tls.Certificate{w.httpsServer.cert}, Certificates: []tls.Certificate{web.httpsServer.cert},
MinVersion: tls.VersionTLS12, MinVersion: tls.VersionTLS12,
RootCAs: Context.tlsRoots, RootCAs: Context.tlsRoots,
CipherSuites: Context.tlsCiphers, CipherSuites: Context.tlsCiphers,
@ -181,7 +181,7 @@ func (w *Web) httpServerLoop() {
} }
printHTTPAddresses("https") printHTTPAddresses("https")
err := w.httpsServer.server.ListenAndServeTLS("", "") err := web.httpsServer.server.ListenAndServeTLS("", "")
if err != http.ErrServerClosed { if err != http.ErrServerClosed {
cleanupAlways() cleanupAlways()
log.Fatal(err) log.Fatal(err)

View File

@ -30,7 +30,7 @@ type NetInterface struct {
func GetValidNetInterfaces() ([]net.Interface, error) { func GetValidNetInterfaces() ([]net.Interface, error) {
ifaces, err := net.Interfaces() ifaces, err := net.Interfaces()
if err != nil { if err != nil {
return nil, fmt.Errorf("Couldn't get list of interfaces: %s", err) return nil, fmt.Errorf("couldn't get list of interfaces: %s", err)
} }
netIfaces := []net.Interface{} netIfaces := []net.Interface{}