diff --git a/.github/workflows/go-test-build.yaml b/.github/workflows/go-test-build.yaml new file mode 100644 index 0000000..f7cd79d --- /dev/null +++ b/.github/workflows/go-test-build.yaml @@ -0,0 +1,20 @@ +name: go-test-build +on: + push: + pull_request: + +jobs: + go-test-build: + runs-on: ubuntu-latest + container: + image: ghcr.io/catthehacker/ubuntu:runner-latest + strategy: + matrix: + go: [ "1.22", "1.21" ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + - run: go test -v ./... + - run: go build -o main main.go diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml new file mode 100644 index 0000000..bece822 --- /dev/null +++ b/.github/workflows/golangci-lint.yaml @@ -0,0 +1,19 @@ +name: golangci-lint +on: + push: + pull_request: + +jobs: + goglangci-lint: + runs-on: ubuntu-latest + container: + image: ghcr.io/catthehacker/ubuntu:runner-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v5 + with: + go-version: "1.22" + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61 diff --git a/.github/workflows/nix-check-build.yaml b/.github/workflows/nix-check-build.yaml new file mode 100644 index 0000000..8ca1dd9 --- /dev/null +++ b/.github/workflows/nix-check-build.yaml @@ -0,0 +1,15 @@ +name: nix-check-build +on: + push: + pull_request: + +jobs: + nix-check-build: + runs-on: ubuntu-latest + container: + image: ghcr.io/catthehacker/ubuntu:runner-latest + steps: + - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v27 + - run: nix flake check + - run: nix build diff --git a/.gitignore b/.gitignore index b2be92b..2bbdbfe 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.direnv result diff --git a/main.go b/main.go index 1ce1788..a361a6c 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,10 @@ func main() { panic(err) } defer input.Close() - input.NonBlock() + if err := input.NonBlock(); err != nil { + slog.Error("Failed to set non-blocking mode", "error", err) + os.Exit(1) + } // Start metrics server srvCtx, srvCancel := context.WithCancel(context.Background()) @@ -54,12 +57,14 @@ func main() { } go func() { <-ctx.Done() - srv.Shutdown(context.Background()) + _ = srv.Shutdown(context.Background()) srvCancel() }() slog.Info("Starting metrics server", "addr", srv.Addr) - srv.ListenAndServe() + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + slog.Warn("Failed to start metrics server", "error", err) + } }() // Listen for context cancellation @@ -84,7 +89,7 @@ func main() { continue } slog.Error("Error reading from input device", "error", err) - mbus.StopTalking() + _ = mbus.StopTalking() os.Exit(1) } if ev.Code == evdev.KEY_F24 && ev.Value == 1 { @@ -104,15 +109,15 @@ func main() { for v := range debouncer.C { if v { - mbus.StartTalking() + _ = mbus.StartTalking() slog.Info("Started talking") } else { - mbus.StopTalking() + _ = mbus.StopTalking() slog.Info("Stopped talking") } } - mbus.StopTalking() + _ = mbus.StopTalking() <-srvCtx.Done() slog.Info("Exiting") }