From dde75e9c630cb804f9ddb15df44b70faa657699e Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Sun, 2 Apr 2023 22:36:13 -0600 Subject: [PATCH] Linting fixes Signed-off-by: Jacob Weinstock --- cmd/boots/dhcp.go | 6 +++--- cmd/boots/http.go | 20 ++++++++++---------- cmd/boots/ipxe.go | 2 +- cmd/boots/main.go | 13 +++++-------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/cmd/boots/dhcp.go b/cmd/boots/dhcp.go index 45680296..c67d8d35 100644 --- a/cmd/boots/dhcp.go +++ b/cmd/boots/dhcp.go @@ -36,7 +36,7 @@ func (d *dhcpConfig) serveDHCP(ctx context.Context, log logr.Logger) error { return e }) <-ctx.Done() - listener.Shutdown() + _ = listener.Shutdown() err := g.Wait() log.Info("shutting down dhcp server") return err @@ -91,7 +91,7 @@ func (d *dhcpConfig) addFlags(fs *flag.FlagSet) { return nil }) // This sets the default value for the flag when coupled with fs.Func. - fs.Set("dhcp-addr", "0.0.0.0:67") + _ = fs.Set("dhcp-addr", "0.0.0.0:67") fs.Func("dhcp-public-ip", "[dhcp] public IP address where Boots will be available. Used for DHCP option 54", func(s string) error { var p netaddr.IP @@ -115,7 +115,7 @@ func (d *dhcpConfig) addFlags(fs *flag.FlagSet) { d.handler.Netboot.IPXEScriptURL = &url.URL{Scheme: "http", Host: p.String(), Path: "/auto.ipxe"} return nil }) - fs.Set("dhcp-public-ip", "0.0.0.0") + _ = fs.Set("dhcp-public-ip", "0.0.0.0") fs.Func("ipxe-remote-tftp-addr", "[dhcp] remote IP:Port where iPXE binaries are served via TFTP.", func(s string) error { if s == "" { return nil diff --git a/cmd/boots/http.go b/cmd/boots/http.go index e734fef5..1d6baaf0 100644 --- a/cmd/boots/http.go +++ b/cmd/boots/http.go @@ -77,30 +77,30 @@ func (h *httpConfig) addFlags(fs *flag.FlagSet) { }) } -func (c *httpConfig) serveHTTP(ctx context.Context, log logr.Logger, ipxeBinaryHandler stdhttp.HandlerFunc, finder backend.HardwareFinder) error { +func (h *httpConfig) serveHTTP(ctx context.Context, log logr.Logger, ipxeBinaryHandler stdhttp.HandlerFunc, finder backend.HardwareFinder) error { httpServer := &http.Config{ GitRev: GitRev, StartTime: startTime, Logger: log, - TrustedProxies: c.trustedProxies, + TrustedProxies: h.trustedProxies, IPXEScript: &http.IPXEScript{ Finder: finder, Logger: log, - OsieURL: c.osieURL, - ExtraKernelParams: strings.Split(c.extraKernelArgs, " "), - SyslogFQDN: c.publicSyslogIP, - TinkServerTLS: c.tinkServerTLS, - TinkServerGRPCAddr: c.tinkServerGRPCAddr, + OsieURL: h.osieURL, + ExtraKernelParams: strings.Split(h.extraKernelArgs, " "), + SyslogFQDN: h.publicSyslogIP, + TinkServerTLS: h.tinkServerTLS, + TinkServerGRPCAddr: h.tinkServerGRPCAddr, }, } - srv := &stdhttp.Server{} + srv := &stdhttp.Server{} //nolint: gosec // Slowloris is handled by httpServer.ServeHTTP g, ctx := errgroup.WithContext(ctx) g.Go(func() error { - return httpServer.ServeHTTP(srv, c.addr, ipxeBinaryHandler) + return httpServer.ServeHTTP(srv, h.addr, ipxeBinaryHandler) }) <-ctx.Done() - go srv.Shutdown(ctx) + go func() { _ = srv.Shutdown(ctx) }() time.AfterFunc(time.Second*5, func() { srv.Close() }) err := g.Wait() if errors.Is(err, stdhttp.ErrServerClosed) { diff --git a/cmd/boots/ipxe.go b/cmd/boots/ipxe.go index 934ffe02..731b7e6a 100644 --- a/cmd/boots/ipxe.go +++ b/cmd/boots/ipxe.go @@ -39,7 +39,7 @@ func (i *ipxeConfig) addTFTPFlags(fs *flag.FlagSet) { return nil }) // This sets the default value for the flag when coupled with fs.Func. - fs.Set("ipxe-tftp-addr", "0.0.0.0:69") + _ = fs.Set("ipxe-tftp-addr", "0.0.0.0:69") // tftp timeout fs.DurationVar(&i.TFTP.Timeout, "ipxe-tftp-timeout", time.Second*5, "[ipxe] local iPXE TFTP server requests timeout.") diff --git a/cmd/boots/main.go b/cmd/boots/main.go index 5f63f040..30864afc 100644 --- a/cmd/boots/main.go +++ b/cmd/boots/main.go @@ -24,13 +24,11 @@ import ( "golang.org/x/sync/errgroup" ) -var ( - // GitRev is the git revision of the build. It is set by the Makefile. - GitRev = "unknown (use make)" -) - const name = "boots" +// GitRev is the git revision of the build. It is set by the Makefile. +var GitRev = "unknown (use make)" + type config struct { // loglevel is the log level for boots. logLevel string @@ -71,8 +69,7 @@ func main() { fs := flag.NewFlagSet(name, flag.ExitOnError) cli := newCLI(cfg, fs) if err := cli.Parse(os.Args[1:]); err != nil { - //fmt.Printf("type %T\n", err) - //fmt.Printf("error parsing cli, %v\n", err) + fmt.Printf("error parsing cli, %v\n", err) os.Exit(1) } @@ -101,7 +98,7 @@ func main() { lg := log.WithValues("service", "github.com/tinkerbell/boots").WithName("github.com/tinkerbell/ipxedust") fn, err := cfg.ipxe.tftpServer(lg) if err != nil { - return nil + return err } return fn(ctx) })