Fix most of golangci-lint errors in the pixiecore package, keep unused logging function and unchecked errors in example

This commit is contained in:
Stefan Majer 2019-09-22 11:58:59 +02:00 committed by Dave Anderson
parent 603e85bc4c
commit f47ae40332
5 changed files with 14 additions and 18 deletions

View File

@ -257,7 +257,7 @@ func (b *apibooter) ReadBootFile(id ID) (io.ReadCloser, int64, error) {
} }
var ( var (
ret io.ReadCloser ret io.ReadCloser
sz int64 = -1 sz int64
) )
if u.Scheme == "file" { if u.Scheme == "file" {
// TODO serveFile // TODO serveFile
@ -284,9 +284,9 @@ func (b *apibooter) ReadBootFile(id ID) (io.ReadCloser, int64, error) {
} }
ret, sz, err = resp.Body, resp.ContentLength, nil ret, sz, err = resp.Body, resp.ContentLength, nil
} if err != nil {
if err != nil { return nil, -1, err
return nil, -1, err }
} }
return ret, sz, nil return ret, sz, nil
} }

View File

@ -2,12 +2,13 @@ package cli
import ( import (
"fmt" "fmt"
"net"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.universe.tf/netboot/dhcp6" "go.universe.tf/netboot/dhcp6"
"go.universe.tf/netboot/dhcp6/pool" "go.universe.tf/netboot/dhcp6/pool"
"go.universe.tf/netboot/pixiecore" "go.universe.tf/netboot/pixiecore"
"net"
"strings"
) )
// pixiecore bootipv6 --listen-addr=2001:db8:f00f:cafe::4/64 --httpboot-url=http://[2001:db8:f00f:cafe::4]/bootx64.efi --ipxe-url=http://[2001:db8:f00f:cafe::4]/script.ipxe // pixiecore bootipv6 --listen-addr=2001:db8:f00f:cafe::4/64 --httpboot-url=http://[2001:db8:f00f:cafe::4]/bootx64.efi --ipxe-url=http://[2001:db8:f00f:cafe::4]/script.ipxe
@ -41,7 +42,6 @@ var bootIPv6Cmd = &cobra.Command{
if addr == "" { if addr == "" {
fatalf("Please specify address to bind to") fatalf("Please specify address to bind to")
} else {
} }
if ipxeURL == "" { if ipxeURL == "" {
fatalf("Please specify ipxe config file url") fatalf("Please specify ipxe config file url")

View File

@ -2,13 +2,14 @@ package cli
import ( import (
"fmt" "fmt"
"net"
"strings"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.universe.tf/netboot/dhcp6" "go.universe.tf/netboot/dhcp6"
"go.universe.tf/netboot/dhcp6/pool" "go.universe.tf/netboot/dhcp6/pool"
"go.universe.tf/netboot/pixiecore" "go.universe.tf/netboot/pixiecore"
"net"
"strings"
"time"
) )
// pixiecore ipv6api --listen-addr=2001:db8:f00f:cafe::4 --api-request-url=http://[2001:db8:f00f:cafe::4]:8888 // pixiecore ipv6api --listen-addr=2001:db8:f00f:cafe::4 --api-request-url=http://[2001:db8:f00f:cafe::4]:8888
@ -42,7 +43,6 @@ var ipv6ApiCmd = &cobra.Command{
if addr == "" { if addr == "" {
fatalf("Please specify address to bind to") fatalf("Please specify address to bind to")
} else {
} }
if apiURL == "" { if apiURL == "" {
fatalf("Please specify ipxe config file url") fatalf("Please specify ipxe config file url")

View File

@ -22,7 +22,6 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"sync"
"testing" "testing"
) )
@ -34,8 +33,6 @@ func (b booterFunc) ReadBootFile(id ID) (io.ReadCloser, int64, error) {
} }
func (b booterFunc) WriteBootFile(id ID, r io.Reader) error { return errors.New("no") } func (b booterFunc) WriteBootFile(id ID, r io.Reader) error { return errors.New("no") }
var logSync sync.Mutex
func TestIpxe(t *testing.T) { func TestIpxe(t *testing.T) {
booter := func(m Machine) (*Spec, error) { booter := func(m Machine) (*Spec, error) {
return &Spec{ return &Spec{

View File

@ -60,12 +60,11 @@ func extractInfo(path string) (net.HardwareAddr, int, error) {
} }
func (s *Server) logTFTPTransfer(clientAddr net.Addr, path string, err error) { func (s *Server) logTFTPTransfer(clientAddr net.Addr, path string, err error) {
mac, _, err := extractInfo(path) mac, _, pathErr := extractInfo(path)
if err != nil { if pathErr != nil {
// Unknown path, nothing to log. s.log("TFTP", "unable to extract mac from request:%v", pathErr)
return return
} }
if err != nil { if err != nil {
s.log("TFTP", "Send of %q to %s failed: %s", path, clientAddr, err) s.log("TFTP", "Send of %q to %s failed: %s", path, clientAddr, err)
} else { } else {