*: 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

@@ -227,7 +227,7 @@ func (s *Server) Start() error {
// TODO: don't close if interface and addresses are the same
if s.conn != nil {
s.closeConn()
_ = s.closeConn()
}
iface, err := net.InterfaceByName(s.conf.InterfaceName)
@@ -251,7 +251,7 @@ func (s *Server) Start() error {
if err != nil && !s.stopping {
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.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)
func (s *Server) AddStaticLease(l Lease) error {
if len(l.IP) != 4 {
return fmt.Errorf("Invalid IP")
return fmt.Errorf("invalid IP")
}
if len(l.HWAddr) != 6 {
return fmt.Errorf("Invalid MAC")
return fmt.Errorf("invalid MAC")
}
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 {
var newLeases []*Lease
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 {
return fmt.Errorf("Static lease with the same IP already exists")
return fmt.Errorf("static lease with the same IP already exists")
}
continue
}
@@ -654,7 +654,7 @@ func (s *Server) rmDynamicLeaseWithIP(ip net.IP) error {
func (s *Server) rmLease(l Lease) error {
var newLeases []*Lease
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) ||
lease.Hostname != l.Hostname {
return fmt.Errorf("Lease not found")
@@ -671,17 +671,17 @@ func (s *Server) rmLease(l Lease) error {
// RemoveStaticLease removes a static lease (thread-safe)
func (s *Server) RemoveStaticLease(l Lease) error {
if len(l.IP) != 4 {
return fmt.Errorf("Invalid IP")
return fmt.Errorf("invalid IP")
}
if len(l.HWAddr) != 6 {
return fmt.Errorf("Invalid MAC")
return fmt.Errorf("invalid MAC")
}
s.leasesLock.Lock()
if s.findReservedHWaddr(l.IP) == nil {
s.leasesLock.Unlock()
return fmt.Errorf("Lease not found")
return fmt.Errorf("lease not found")
}
err := s.rmLease(l)

View File

@@ -33,7 +33,7 @@ func HasStaticIP(ifaceName string) (bool, error) {
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
@@ -46,7 +46,7 @@ func SetStaticIP(ifaceName string) error {
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
@@ -114,7 +114,7 @@ func getGatewayIP(ifaceName string) string {
func setStaticIPDhcpdConf(ifaceName string) error {
ip := util.GetSubnet(ifaceName)
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)
@@ -198,7 +198,7 @@ func setStaticIPDarwin(ifaceName string) error {
return err
}
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
@@ -208,7 +208,7 @@ func setStaticIPDarwin(ifaceName string) error {
return err
}
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
@@ -220,7 +220,7 @@ func getCurrentHardwarePortInfo(ifaceName string) (hardwarePortInfo, error) {
m := getNetworkSetupHardwareReports()
hardwarePort, ok := m[ifaceName]
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)
@@ -274,7 +274,7 @@ func getHardwarePortInfo(hardwarePort string) (hardwarePortInfo, error) {
match := re.FindStringSubmatch(out)
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
@@ -300,7 +300,7 @@ func getEtcResolvConfServers() ([]string, error) {
matches := re.FindAllStringSubmatch(string(body), -1)
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)

View File

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