Add workflows and fix linter errors
All checks were successful
All checks were successful
This commit is contained in:
parent
4f594f7412
commit
84fcfdde62
20
.github/workflows/go-test-build.yaml
vendored
Normal file
20
.github/workflows/go-test-build.yaml
vendored
Normal file
@ -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
|
19
.github/workflows/golangci-lint.yaml
vendored
Normal file
19
.github/workflows/golangci-lint.yaml
vendored
Normal file
@ -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
|
15
.github/workflows/nix-check-build.yaml
vendored
Normal file
15
.github/workflows/nix-check-build.yaml
vendored
Normal file
@ -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
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
|
.direnv
|
||||||
result
|
result
|
||||||
|
19
main.go
19
main.go
@ -40,7 +40,10 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer input.Close()
|
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
|
// Start metrics server
|
||||||
srvCtx, srvCancel := context.WithCancel(context.Background())
|
srvCtx, srvCancel := context.WithCancel(context.Background())
|
||||||
@ -54,12 +57,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
srv.Shutdown(context.Background())
|
_ = srv.Shutdown(context.Background())
|
||||||
srvCancel()
|
srvCancel()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
slog.Info("Starting metrics server", "addr", srv.Addr)
|
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
|
// Listen for context cancellation
|
||||||
@ -84,7 +89,7 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
slog.Error("Error reading from input device", "error", err)
|
slog.Error("Error reading from input device", "error", err)
|
||||||
mbus.StopTalking()
|
_ = mbus.StopTalking()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if ev.Code == evdev.KEY_F24 && ev.Value == 1 {
|
if ev.Code == evdev.KEY_F24 && ev.Value == 1 {
|
||||||
@ -104,15 +109,15 @@ func main() {
|
|||||||
|
|
||||||
for v := range debouncer.C {
|
for v := range debouncer.C {
|
||||||
if v {
|
if v {
|
||||||
mbus.StartTalking()
|
_ = mbus.StartTalking()
|
||||||
slog.Info("Started talking")
|
slog.Info("Started talking")
|
||||||
} else {
|
} else {
|
||||||
mbus.StopTalking()
|
_ = mbus.StopTalking()
|
||||||
slog.Info("Stopped talking")
|
slog.Info("Stopped talking")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mbus.StopTalking()
|
_ = mbus.StopTalking()
|
||||||
<-srvCtx.Done()
|
<-srvCtx.Done()
|
||||||
slog.Info("Exiting")
|
slog.Info("Exiting")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user