*: enable nogo (go linter)

Also fix a bunch of small issues in our codebase, whoops.

This is ran automatically on `bazel build`.

Change-Id: If49ba956b4e2380344a765c30cd84ab760fc4c68
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1849
Reviewed-by: palid <palid@hackerspace.pl>
changes/49/1849/4
q3k 2024-01-15 13:19:16 +00:00 committed by q3k
parent 2ea09a804d
commit 939eaaaccb
8 changed files with 19 additions and 11 deletions

8
BUILD
View File

@ -33,3 +33,11 @@ load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
buildifier(
name = "buildifier",
)
load("@io_bazel_rules_go//go:def.bzl", "nogo")
nogo(
name = "nogo",
vet = True,
visibility = ["//visibility:public"], # must have public visibility
)

View File

@ -119,7 +119,7 @@ go_repository(
go_rules_dependencies()
go_register_toolchains(go_version = "1.20.5")
go_register_toolchains(go_version = "1.20.5", nogo = "@//:nogo")
http_archive(
name = "com_github_grpc_grpc",

View File

@ -114,7 +114,7 @@ func (c *Client) logIn(ctx context.Context) error {
return fmt.Errorf("invalid username prompt: %v", err)
}
if err := c.writeLine(ctx, c.username); err != nil {
return fmt.Errorf("could not write username: %v")
return fmt.Errorf("could not write username: %v", err)
}
// Provide password.
@ -126,7 +126,7 @@ func (c *Client) logIn(ctx context.Context) error {
return fmt.Errorf("invalid password prompt: %v", err)
}
if err := c.writeLine(ctx, c.password); err != nil {
return fmt.Errorf("could not write password: %v")
return fmt.Errorf("could not write password: %v", err)
}
// Get unprivileged prompt.
@ -141,7 +141,7 @@ func (c *Client) logIn(ctx context.Context) error {
// Enable privileged mode.
if err := c.writeLine(ctx, "enable"); err != nil {
return fmt.Errorf("could not write enable: %v")
return fmt.Errorf("could not write enable: %v", err)
}
// Provide password (again)
@ -153,7 +153,7 @@ func (c *Client) logIn(ctx context.Context) error {
return fmt.Errorf("invalid password prompt: %v", err)
}
if err := c.writeLine(ctx, c.password); err != nil {
return fmt.Errorf("could not write password: %v")
return fmt.Errorf("could not write password: %v", err)
}
// Get privileged prompt.

View File

@ -44,7 +44,7 @@ func TestParse(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
got, err := parseToml([]byte(test.data))
if err != nil {
t.Fatalf("could not parse config: %w", err)
t.Fatalf("could not parse config: %v", err)
}
if diff := deep.Equal(test.want, got); diff != nil {
t.Fatal(diff)

View File

@ -68,7 +68,7 @@ func TestHTTPRemoteClient(t *testing.T) {
}
} else {
if te.wantIP != nil || te.wantPort != 0 {
t.Errorf("%d: wanted %v %d, got failure", te.wantIP, te.wantPort)
t.Errorf("%d: wanted %v %d, got failure", i, te.wantIP, te.wantPort)
}
}
}

View File

@ -49,7 +49,7 @@ type creds struct {
func loadDeveloperCredentials() (*creds, error) {
path, err := DeveloperCredentialsLocation()
if err != nil {
return nil, fmt.Errorf("DeveloperCredentialsLocation: %w")
return nil, fmt.Errorf("DeveloperCredentialsLocation: %w", err)
}
c := creds{}

View File

@ -15,7 +15,7 @@ func TestWarsawDate(t *testing.T) {
}
ti, err := time.ParseInLocation("2006/01/02 15:04", s, warsaw)
if err != nil {
t.Fatal("could not parse test time %q: %v", s, err)
t.Fatalf("could not parse test time %q: %v", s, err)
}
return EventTime{
Time: ti,
@ -25,7 +25,7 @@ func TestWarsawDate(t *testing.T) {
t.Helper()
ti, err := time.Parse("2006/01/02", s)
if err != nil {
t.Fatal("could not parse test day %q: %v", s, err)
t.Fatalf("could not parse test day %q: %v", s, err)
}
return EventTime{
Time: ti,

View File

@ -41,7 +41,7 @@ func (e eventBySooner) Less(i, j int) bool {
func parseUpcomingEvents(now time.Time, data io.Reader) ([]*UpcomingEvent, error) {
cal, err := ics.ParseCalendar(data)
if err != nil {
return nil, fmt.Errorf("ParseCalendar(%q): %w", err)
return nil, fmt.Errorf("ParseCalendar(%q): %w", data, err)
}
var out []*UpcomingEvent