Compare commits

...

2 Commits

Author SHA1 Message Date
585b4d4c14 add golang-ci config + action
Some checks failed
CI / Lint (push) Has been cancelled
Auto-Update Go Modules / update-go-modules (push) Has been cancelled
2025-03-10 15:32:25 +00:00
29e6c2e8aa lint fixes 2025-03-10 15:32:10 +00:00
9 changed files with 102 additions and 15 deletions

29
.github/workflows/golang-ci.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: CI
on:
push:
branches: [ "main" ]
paths:
- '**.go'
pull_request:
branches: [ "main" ]
paths:
- '**.go'
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
timeout-minutes: 3
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- name: Run golangci-lint
run: golangci-lint run ./...

54
.golangci.yml Normal file
View File

@ -0,0 +1,54 @@
run:
# timeout for analysis, e.g. 30s, 3m, default is 1m
timeout: 3m
# exclude test files
tests: true
linters:
# Set to true runs only fast linters.
# Good option for 'lint on save', pre-commit hook or CI.
fast: true
disable-all: true
enable:
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- gofmt
- gofumpt
- misspell
- unparam
- gosec
- asciicheck
- errname
- gci
- godot
- goimports
- revive
linters-settings:
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
misspell:
locale: UK
errcheck:
check-type-assertions: true
issues:
max-same-issues: 0
max-issues-per-linter: 0
exclude-use-default: false
exclude:
# gosec: Duplicated errcheck checks
- G104
# gosec: integer overflow conversion int -> uint32
- G115

View File

@ -1,3 +1,4 @@
// Package main provides the configuration loading functionality for the vbantxt application.
package main
import (

View File

@ -35,5 +35,4 @@ func TestLoadConfig_Errors(t *testing.T) {
assert.ErrorContains(t, err, tc.err)
})
}
}

View File

@ -1,3 +1,4 @@
// Package vbantxt provides utilities for handling VBAN text errors.
package vbantxt
// Error is used to define sentinel errors.

View File

@ -9,14 +9,14 @@ import (
// Option is a functional option type that allows us to configure the VbanTxt.
type Option func(*VbanTxt)
// WithRateLimit is a functional option to set the ratelimit for requests
// WithRateLimit is a functional option to set the ratelimit for requests.
func WithRateLimit(ratelimit time.Duration) Option {
return func(vt *VbanTxt) {
vt.ratelimit = ratelimit
}
}
// WithBPSOpt is a functional option to set the bps index for {VbanTxt}.packet
// WithBPSOpt is a functional option to set the bps index for {VbanTxt}.packet.
func WithBPSOpt(bps int) Option {
return func(vt *VbanTxt) {
bpsIndex := indexOf(BpsOpts, bps)
@ -28,7 +28,7 @@ func WithBPSOpt(bps int) Option {
}
}
// WithChannel is a functional option to set the channel for {VbanTxt}.packet
// WithChannel is a functional option to set the channel for {VbanTxt}.packet.
func WithChannel(channel int) Option {
return func(vt *VbanTxt) {
vt.packet.channel = channel

View File

@ -13,9 +13,12 @@ const (
headerSz = 4 + 1 + 1 + 1 + 1 + 16 + 4
)
var BpsOpts = []int{0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
// BpsOpts defines the available baud rate options.
var BpsOpts = []int{
0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
38400, 57600, 115200, 128000, 230400, 250000, 256000, 460800, 921600,
1000000, 1500000, 2000000, 3000000}
1000000, 1500000, 2000000, 3000000,
}
type packet struct {
streamname []byte
@ -39,17 +42,17 @@ func newPacket(streamname string) packet {
}
}
// sr defines the samplerate for the request
// sr defines the samplerate for the request.
func (p *packet) sr() byte {
return byte(vbanProtocolTxt + p.bpsIndex)
}
// nbc defines the channel of the request
// nbc defines the channel of the request.
func (p *packet) nbc() byte {
return byte(p.channel)
}
// header returns a fully formed packet header
// header returns a fully formed packet header.
func (p *packet) header() []byte {
p.hbuf.Reset()
p.hbuf.WriteString("VBAN")
@ -62,7 +65,7 @@ func (p *packet) header() []byte {
return p.hbuf.Bytes()
}
// bumpFrameCounter increments the frame counter by 1
// bumpFrameCounter increments the frame counter by 1.
func (p *packet) bumpFrameCounter() {
x := binary.LittleEndian.Uint32(p.framecounter)
binary.LittleEndian.PutUint32(p.framecounter, x+1)

View File

@ -7,12 +7,12 @@ import (
log "github.com/sirupsen/logrus"
)
// udpConn represents the UDP client
// udpConn represents the UDP client.
type udpConn struct {
conn *net.UDPConn
}
// newUDPConn returns a UDP client
// newUDPConn returns a UDP client.
func newUDPConn(host string, port int) (udpConn, error) {
udpAddr, err := net.ResolveUDPAddr("udp4", fmt.Sprintf("%s:%d", host, port))
if err != nil {
@ -27,7 +27,7 @@ func newUDPConn(host string, port int) (udpConn, error) {
return udpConn{conn: conn}, nil
}
// Write implements the io.WriteCloser interface
// Write implements the io.WriteCloser interface.
func (u udpConn) Write(buf []byte) (int, error) {
n, err := u.conn.Write(buf)
if err != nil {
@ -38,7 +38,7 @@ func (u udpConn) Write(buf []byte) (int, error) {
return n, nil
}
// Close implements the io.WriteCloser interface
// Close implements the io.WriteCloser interface.
func (u udpConn) Close() error {
err := u.conn.Close()
if err != nil {

View File

@ -49,7 +49,7 @@ func (vt VbanTxt) Send(cmd string) error {
return nil
}
// Close is responsible for closing the UDP Client connection
// Close is responsible for closing the UDP Client connection.
func (vt VbanTxt) Close() error {
err := vt.udpConn.Close()
if err != nil {