mirror of
https://github.com/onyx-and-iris/vbantxt.git
synced 2026-03-12 13:09:16 +00:00
Compare commits
No commits in common. "87ea26ab03e06645049687a566636fa3b73bef7e" and "ecd16545ab16629a6ff00b910af1427dcd84edf3" have entirely different histories.
87ea26ab03
...
ecd16545ab
13
.github/workflows/golang-ci.yml
vendored
13
.github/workflows/golang-ci.yml
vendored
@ -2,11 +2,11 @@ name: CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ['main']
|
branches: [ "main" ]
|
||||||
paths:
|
paths:
|
||||||
- '**.go'
|
- '**.go'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: ['main']
|
branches: [ "main" ]
|
||||||
paths:
|
paths:
|
||||||
- '**.go'
|
- '**.go'
|
||||||
jobs:
|
jobs:
|
||||||
@ -23,8 +23,7 @@ jobs:
|
|||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.24'
|
go-version: '1.24'
|
||||||
- name: golangci-lint
|
- name: Install golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v9
|
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||||
with:
|
- name: Run golangci-lint
|
||||||
version: v2.6.0
|
run: golangci-lint run ./...
|
||||||
args: --config .golangci.yml
|
|
||||||
134
.golangci.yml
134
.golangci.yml
@ -1,110 +1,54 @@
|
|||||||
version: '2'
|
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
# timeout for analysis, e.g. 30s, 3m, default is 1m
|
||||||
timeout: 3m
|
timeout: 3m
|
||||||
|
# exclude test files
|
||||||
tests: true
|
tests: true
|
||||||
go: '1.24'
|
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
enable:
|
# Set to true runs only fast linters.
|
||||||
# Default enabled linters
|
# Good option for 'lint on save', pre-commit hook or CI.
|
||||||
- errcheck # Check for unchecked errors
|
fast: true
|
||||||
- govet # Go's built-in vetting tool
|
|
||||||
- ineffassign # Detect ineffectual assignments
|
disable-all: true
|
||||||
- staticcheck # Advanced static analysis
|
|
||||||
- unused # Check for unused code
|
enable:
|
||||||
# Additional useful linters
|
- gosimple
|
||||||
- misspell # Detect common misspellings
|
- govet
|
||||||
- unparam # Check for unused function parameters
|
- ineffassign
|
||||||
- gosec # Security checks
|
- staticcheck
|
||||||
- asciicheck # Check for non-ASCII characters
|
- unused
|
||||||
- errname # Check error variable names
|
- gofmt
|
||||||
- godot # Check for missing periods in comments
|
- gofumpt
|
||||||
- revive # Highly configurable linter for style and correctness
|
- misspell
|
||||||
- gocritic # Detect code issues and suggest improvements
|
- unparam
|
||||||
- gocyclo # Check for cyclomatic complexity
|
- gosec
|
||||||
- dupl # Check for code duplication
|
- asciicheck
|
||||||
- predeclared # Check for shadowing of predeclared identifiers
|
- errname
|
||||||
- copyloopvar # Check for loop variable capture in goroutines
|
- gci
|
||||||
- errorlint # Check for common mistakes in error handling
|
- godot
|
||||||
- goconst # Check for repeated strings that could be constants
|
- goimports
|
||||||
- gosmopolitan # Check for non-portable code
|
- revive
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
gofmt:
|
||||||
|
rewrite-rules:
|
||||||
|
- pattern: 'interface{}'
|
||||||
|
replacement: 'any'
|
||||||
|
- pattern: 'a[b:len(a)]'
|
||||||
|
replacement: 'a[b:]'
|
||||||
|
|
||||||
settings:
|
|
||||||
misspell:
|
misspell:
|
||||||
locale: UK
|
locale: UK
|
||||||
|
|
||||||
errcheck:
|
errcheck:
|
||||||
check-type-assertions: true
|
check-type-assertions: true
|
||||||
check-blank: true
|
|
||||||
|
|
||||||
revive:
|
|
||||||
rules:
|
|
||||||
# Code quality and style
|
|
||||||
- name: exported
|
|
||||||
arguments:
|
|
||||||
- 'checkPrivateReceivers'
|
|
||||||
- 'sayRepetitiveInsteadOfStutters'
|
|
||||||
- name: var-naming
|
|
||||||
- name: package-comments
|
|
||||||
- name: range-val-in-closure
|
|
||||||
- name: time-naming
|
|
||||||
- name: context-as-argument
|
|
||||||
- name: context-keys-type
|
|
||||||
- name: dot-imports
|
|
||||||
- name: empty-block
|
|
||||||
- name: error-return
|
|
||||||
- name: error-strings
|
|
||||||
- name: error-naming
|
|
||||||
- name: if-return
|
|
||||||
- name: increment-decrement
|
|
||||||
- name: indent-error-flow
|
|
||||||
- name: receiver-naming
|
|
||||||
- name: redefines-builtin-id
|
|
||||||
- name: superfluous-else
|
|
||||||
- name: unexported-return
|
|
||||||
- name: unreachable-code
|
|
||||||
- name: unused-parameter
|
|
||||||
- name: var-declaration
|
|
||||||
- name: blank-imports
|
|
||||||
|
|
||||||
# Disabled rules (can be enabled if needed)
|
|
||||||
# - name: line-length-limit
|
|
||||||
# arguments: [120]
|
|
||||||
# - name: function-length
|
|
||||||
# arguments: [50, 0]
|
|
||||||
# - name: cyclomatic
|
|
||||||
# arguments: [10]
|
|
||||||
|
|
||||||
gosec:
|
|
||||||
excludes:
|
|
||||||
- G104 # Duplicated errcheck checks
|
|
||||||
- G115 # integer overflow conversion int -> uint32
|
|
||||||
|
|
||||||
# Formatters configuration
|
|
||||||
formatters:
|
|
||||||
# Enable specific formatters
|
|
||||||
enable:
|
|
||||||
- gofumpt # Stricter gofmt alternative
|
|
||||||
- goimports # Organizes imports
|
|
||||||
- gci # Controls import order/grouping
|
|
||||||
- golines # Enforces line length
|
|
||||||
|
|
||||||
# Formatter-specific settings
|
|
||||||
settings:
|
|
||||||
goimports:
|
|
||||||
local-prefixes: [github.com/onyx-and-iris/vbantxt]
|
|
||||||
|
|
||||||
gci:
|
|
||||||
# Define import sections order
|
|
||||||
sections:
|
|
||||||
- standard # Standard library
|
|
||||||
- default # Everything else
|
|
||||||
- prefix(github.com/onyx-and-iris/vbantxt) # Current module
|
|
||||||
|
|
||||||
gofumpt:
|
|
||||||
extra-rules: true # Enable additional formatting rules
|
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
max-same-issues: 0
|
max-same-issues: 0
|
||||||
max-issues-per-linter: 0
|
max-issues-per-linter: 0
|
||||||
|
exclude-use-default: false
|
||||||
|
exclude:
|
||||||
|
# gosec: Duplicated errcheck checks
|
||||||
|
- G104
|
||||||
|
# gosec: integer overflow conversion int -> uint32
|
||||||
|
- G115
|
||||||
|
|||||||
11
CHANGELOG.md
11
CHANGELOG.md
@ -11,17 +11,6 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
|||||||
|
|
||||||
- [x]
|
- [x]
|
||||||
|
|
||||||
# [0.6.0] - 2025-02-14
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- streamname length validation added to {packet} factory method.
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- {packet}.bspIndex now defaults to *indexOf(BpsOpts, 256000)*.
|
|
||||||
- this doesn't affect the CLI which already defaulted to 256000.
|
|
||||||
- WithBPSOpt and WithChannel functional options now log at warn level if passed out of bounds value. They will fallback to valid defaults.
|
|
||||||
|
|
||||||
# [0.5.0] - 2025-06-25
|
# [0.5.0] - 2025-06-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
11
Taskfile.yml
11
Taskfile.yml
@ -9,7 +9,6 @@ vars:
|
|||||||
|
|
||||||
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
||||||
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
||||||
MACOS: '{{.BIN_DIR}}/{{.PROGRAM}}_darwin_amd64'
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
default:
|
||||||
@ -23,7 +22,7 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- task: build-windows
|
- task: build-windows
|
||||||
- task: build-linux
|
- task: build-linux
|
||||||
- task: build-macos
|
|
||||||
vet:
|
vet:
|
||||||
desc: Vet the code
|
desc: Vet the code
|
||||||
deps: [fmt]
|
deps: [fmt]
|
||||||
@ -39,19 +38,11 @@ tasks:
|
|||||||
desc: Build the vbantxt project for Windows
|
desc: Build the vbantxt project for Windows
|
||||||
cmds:
|
cmds:
|
||||||
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
- GOOS=windows GOARCH=amd64 go build -o {{.WINDOWS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
||||||
internal: true
|
|
||||||
|
|
||||||
build-linux:
|
build-linux:
|
||||||
desc: Build the vbantxt project for Linux
|
desc: Build the vbantxt project for Linux
|
||||||
cmds:
|
cmds:
|
||||||
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
||||||
internal: true
|
|
||||||
|
|
||||||
build-macos:
|
|
||||||
desc: Build the vbantxt project for macOS
|
|
||||||
cmds:
|
|
||||||
- GOOS=darwin GOARCH=amd64 go build -o {{.MACOS}} -ldflags="-X main.version={{.VERSION}}" ./cmd/{{.PROGRAM}}/
|
|
||||||
internal: true
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
desc: Run tests
|
desc: Run tests
|
||||||
|
|||||||
@ -11,11 +11,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
|
"github.com/onyx-and-iris/vbantxt"
|
||||||
"github.com/peterbourgon/ff/v4"
|
"github.com/peterbourgon/ff/v4"
|
||||||
"github.com/peterbourgon/ff/v4/ffhelp"
|
"github.com/peterbourgon/ff/v4/ffhelp"
|
||||||
"github.com/peterbourgon/ff/v4/fftoml"
|
"github.com/peterbourgon/ff/v4/fftoml"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/vbantxt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string // Version will be set at build time
|
var version string // Version will be set at build time
|
||||||
@ -33,22 +32,8 @@ type Flags struct {
|
|||||||
Version bool // Version flag
|
Version bool // Version flag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Flags) String() string {
|
|
||||||
return fmt.Sprintf(
|
|
||||||
"Host: %s, Port: %d, Streamname: %s, Bps: %d, Channel: %d, Ratelimit: %dms, ConfigPath: %s, Loglevel: %s",
|
|
||||||
f.Host,
|
|
||||||
f.Port,
|
|
||||||
f.Streamname,
|
|
||||||
f.Bps,
|
|
||||||
f.Channel,
|
|
||||||
f.Ratelimit,
|
|
||||||
f.ConfigPath,
|
|
||||||
f.Loglevel,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func exitOnError(err error) {
|
func exitOnError(err error) {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
_, _ = fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +41,7 @@ func main() {
|
|||||||
var flags Flags
|
var flags Flags
|
||||||
|
|
||||||
// VBAN specific flags
|
// VBAN specific flags
|
||||||
fs := ff.NewFlagSet("vbantxt - A command-line tool for sending text requests over VBAN")
|
fs := ff.NewFlagSet("vbantxt")
|
||||||
fs.StringVar(&flags.Host, 'H', "host", "localhost", "VBAN host")
|
fs.StringVar(&flags.Host, 'H', "host", "localhost", "VBAN host")
|
||||||
fs.IntVar(&flags.Port, 'p', "port", 6980, "VBAN port")
|
fs.IntVar(&flags.Port, 'p', "port", 6980, "VBAN port")
|
||||||
fs.StringVar(&flags.Streamname, 's', "streamname", "Command1", "VBAN stream name")
|
fs.StringVar(&flags.Streamname, 's', "streamname", "Command1", "VBAN stream name")
|
||||||
@ -71,20 +56,8 @@ func main() {
|
|||||||
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
|
defaultConfigPath := filepath.Join(configDir, "vbantxt", "config.toml")
|
||||||
|
|
||||||
// Configuration file and logging flags
|
// Configuration file and logging flags
|
||||||
fs.StringVar(
|
fs.StringVar(&flags.ConfigPath, 'C', "config", defaultConfigPath, "Path to the configuration file")
|
||||||
&flags.ConfigPath,
|
fs.StringVar(&flags.Loglevel, 'l', "loglevel", "warn", "Log level (debug, info, warn, error, fatal, panic)")
|
||||||
'C',
|
|
||||||
"config",
|
|
||||||
defaultConfigPath,
|
|
||||||
"Path to the configuration file",
|
|
||||||
)
|
|
||||||
fs.StringVar(
|
|
||||||
&flags.Loglevel,
|
|
||||||
'l',
|
|
||||||
"loglevel",
|
|
||||||
"warn",
|
|
||||||
"Log level (debug, info, warn, error, fatal, panic)",
|
|
||||||
)
|
|
||||||
fs.BoolVar(&flags.Version, 'v', "version", "Show version information")
|
fs.BoolVar(&flags.Version, 'v', "version", "Show version information")
|
||||||
|
|
||||||
err = ff.Parse(fs, os.Args[1:],
|
err = ff.Parse(fs, os.Args[1:],
|
||||||
@ -102,7 +75,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if flags.Version {
|
if flags.Version {
|
||||||
fmt.Printf("vbantxt version: %s\n", versionFromBuild())
|
if version == "" {
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
exitOnError(errors.New("failed to read build info"))
|
||||||
|
}
|
||||||
|
version = strings.Split(info.Main.Version, "-")[0]
|
||||||
|
}
|
||||||
|
fmt.Printf("vbantxt version: %s\n", version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +92,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.SetLevel(level)
|
log.SetLevel(level)
|
||||||
|
|
||||||
log.Debugf("Loaded configuration: %s", flags.String())
|
log.Debugf("Loaded configuration: %+v", flags)
|
||||||
|
|
||||||
client, closer, err := createClient(&flags)
|
client, closer, err := createClient(&flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -120,24 +100,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
commands := fs.GetArgs()
|
for _, arg := range fs.GetArgs() {
|
||||||
if len(commands) == 0 {
|
err := client.Send(arg)
|
||||||
exitOnError(errors.New("no VBAN commands provided"))
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendCommands(client, commands)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// versionFromBuild retrieves the version information from the build metadata.
|
|
||||||
func versionFromBuild() string {
|
|
||||||
if version == "" {
|
|
||||||
info, ok := debug.ReadBuildInfo()
|
|
||||||
if !ok {
|
|
||||||
exitOnError(errors.New("failed to read build info"))
|
|
||||||
}
|
|
||||||
version = strings.Split(info.Main.Version, "-")[0]
|
|
||||||
}
|
|
||||||
return version
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// createClient creates a new vban client with the provided options.
|
// createClient creates a new vban client with the provided options.
|
||||||
@ -161,14 +129,3 @@ func createClient(flags *Flags) (*vbantxt.VbanTxt, func(), error) {
|
|||||||
|
|
||||||
return client, closer, err
|
return client, closer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendCommands sends a list of commands to the VBAN client.
|
|
||||||
func sendCommands(client *vbantxt.VbanTxt, commands []string) {
|
|
||||||
for _, cmd := range commands {
|
|
||||||
err := client.Send(cmd)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Failed to send command '%s': %v", cmd, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -25,7 +25,7 @@ require (
|
|||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.19 // indirect
|
github.com/mattn/go-runewidth v0.0.19 // indirect
|
||||||
github.com/muesli/termenv v0.16.0 // indirect
|
github.com/muesli/termenv v0.16.0 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||||
|
|||||||
12
go.sum
12
go.sum
@ -18,7 +18,6 @@ github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfa
|
|||||||
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
|
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
|
||||||
github.com/clipperhouse/uax29/v2 v2.6.0 h1:z0cDbUV+aPASdFb2/ndFnS9ts/WNXgTNNGFoKXuhpos=
|
github.com/clipperhouse/uax29/v2 v2.6.0 h1:z0cDbUV+aPASdFb2/ndFnS9ts/WNXgTNNGFoKXuhpos=
|
||||||
github.com/clipperhouse/uax29/v2 v2.6.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
github.com/clipperhouse/uax29/v2 v2.6.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-logfmt/logfmt v0.6.1 h1:4hvbpePJKnIzH1B+8OR/JPbTx37NktoI9LE2QZBBkvE=
|
github.com/go-logfmt/logfmt v0.6.1 h1:4hvbpePJKnIzH1B+8OR/JPbTx37NktoI9LE2QZBBkvE=
|
||||||
@ -38,20 +37,14 @@ github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byF
|
|||||||
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
|
||||||
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
|
||||||
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
|
||||||
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
|
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||||
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||||
github.com/peterbourgon/ff/v4 v4.0.0-beta.1 h1:hV8qRu3V7YfiSMsBSfPfdcznAvPQd3jI5zDddSrDoUc=
|
github.com/peterbourgon/ff/v4 v4.0.0-beta.1 h1:hV8qRu3V7YfiSMsBSfPfdcznAvPQd3jI5zDddSrDoUc=
|
||||||
github.com/peterbourgon/ff/v4 v4.0.0-beta.1/go.mod h1:onQJUKipvCyFmZ1rIYwFAh1BhPOvftb1uhvSI7krNLc=
|
github.com/peterbourgon/ff/v4 v4.0.0-beta.1/go.mod h1:onQJUKipvCyFmZ1rIYwFAh1BhPOvftb1uhvSI7krNLc=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
|
||||||
@ -66,6 +59,5 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33
|
|||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
10
makefile
10
makefile
@ -5,27 +5,24 @@ BIN_DIR := bin
|
|||||||
|
|
||||||
WINDOWS=$(BIN_DIR)/$(PROGRAM)_windows_amd64.exe
|
WINDOWS=$(BIN_DIR)/$(PROGRAM)_windows_amd64.exe
|
||||||
LINUX=$(BIN_DIR)/$(PROGRAM)_linux_amd64
|
LINUX=$(BIN_DIR)/$(PROGRAM)_linux_amd64
|
||||||
MACOS=$(BIN_DIR)/$(PROGRAM)_darwin_amd64
|
|
||||||
VERSION=$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
|
VERSION=$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
|
||||||
|
|
||||||
.DEFAULT_GOAL := build
|
.DEFAULT_GOAL := build
|
||||||
|
|
||||||
.PHONY: fmt vet build windows linux macos test clean
|
.PHONY: fmt vet build windows linux test clean
|
||||||
fmt:
|
fmt:
|
||||||
$(GO) fmt ./...
|
$(GO) fmt ./...
|
||||||
|
|
||||||
vet: fmt
|
vet: fmt
|
||||||
$(GO) vet ./...
|
$(GO) vet ./...
|
||||||
|
|
||||||
build: vet windows linux macos | $(BIN_DIR)
|
build: vet windows linux | $(BIN_DIR)
|
||||||
@echo version: $(VERSION)
|
@echo version: $(VERSION)
|
||||||
|
|
||||||
windows: $(WINDOWS)
|
windows: $(WINDOWS)
|
||||||
|
|
||||||
linux: $(LINUX)
|
linux: $(LINUX)
|
||||||
|
|
||||||
macos: $(MACOS)
|
|
||||||
|
|
||||||
|
|
||||||
$(WINDOWS):
|
$(WINDOWS):
|
||||||
env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
env GOOS=windows GOARCH=amd64 go build -v -o $(WINDOWS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
||||||
@ -33,9 +30,6 @@ $(WINDOWS):
|
|||||||
$(LINUX):
|
$(LINUX):
|
||||||
env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
env GOOS=linux GOARCH=amd64 go build -v -o $(LINUX) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
||||||
|
|
||||||
$(MACOS):
|
|
||||||
env GOOS=darwin GOARCH=amd64 go build -v -o $(MACOS) -ldflags="-s -w -X main.version=$(VERSION)" ./cmd/$(PROGRAM)/
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GO) test ./...
|
$(GO) test ./...
|
||||||
|
|
||||||
|
|||||||
25
option.go
25
option.go
@ -19,37 +19,18 @@ func WithRateLimit(ratelimit time.Duration) Option {
|
|||||||
// 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 {
|
func WithBPSOpt(bps int) Option {
|
||||||
return func(vt *VbanTxt) {
|
return func(vt *VbanTxt) {
|
||||||
defaultBps := BpsOpts[vt.packet.bpsIndex]
|
|
||||||
|
|
||||||
bpsIndex := indexOf(BpsOpts, bps)
|
bpsIndex := indexOf(BpsOpts, bps)
|
||||||
if bpsIndex == -1 {
|
if bpsIndex == -1 {
|
||||||
log.Warnf(
|
log.Warnf("invalid bps value %d, expected one of %v, defaulting to 0", bps, BpsOpts)
|
||||||
"invalid bps value %d, expected one of %v, defaulting to %d",
|
|
||||||
bps,
|
|
||||||
BpsOpts,
|
|
||||||
defaultBps,
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if bpsIndex > 255 {
|
vt.packet.bpsIndex = bpsIndex
|
||||||
log.Warnf("bps index %d too large for uint8, defaulting to %d", bpsIndex, defaultBps)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
vt.packet.bpsIndex = uint8(bpsIndex)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
func WithChannel(channel int) Option {
|
||||||
return func(vt *VbanTxt) {
|
return func(vt *VbanTxt) {
|
||||||
if channel < 0 || channel > 255 {
|
vt.packet.channel = channel
|
||||||
log.Warnf(
|
|
||||||
"channel value %d out of range [0,255], defaulting to %d",
|
|
||||||
channel,
|
|
||||||
vt.packet.channel,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
vt.packet.channel = uint8(channel)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
54
packet.go
54
packet.go
@ -3,7 +3,6 @@ package vbantxt
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
)
|
)
|
||||||
@ -22,39 +21,25 @@ var BpsOpts = []int{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type packet struct {
|
type packet struct {
|
||||||
streamname [streamNameSz]byte
|
streamname []byte
|
||||||
bpsIndex uint8
|
bpsIndex int
|
||||||
channel uint8
|
channel int
|
||||||
framecounter uint32
|
framecounter []byte
|
||||||
hbuf *bytes.Buffer
|
hbuf *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// newPacket creates a new packet with the given stream name and default values for other fields.
|
// newPacket returns a packet struct with default values, framecounter at 0.
|
||||||
// It validates the stream name length and ensures the default baud rate is present in BpsOpts.
|
func newPacket(streamname string) packet {
|
||||||
func newPacket(streamname string) (packet, error) {
|
streamnameBuf := make([]byte, streamNameSz)
|
||||||
if len(streamname) > streamNameSz {
|
copy(streamnameBuf, streamname)
|
||||||
return packet{}, fmt.Errorf(
|
|
||||||
"streamname too long: %d chars, max %d",
|
|
||||||
len(streamname),
|
|
||||||
streamNameSz,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
var streamnameBuf [streamNameSz]byte
|
|
||||||
copy(streamnameBuf[:], streamname)
|
|
||||||
|
|
||||||
bpsIndex := indexOf(BpsOpts, 256000)
|
|
||||||
if bpsIndex == -1 {
|
|
||||||
return packet{}, fmt.Errorf("default baud rate 256000 not found in BpsOpts")
|
|
||||||
}
|
|
||||||
|
|
||||||
return packet{
|
return packet{
|
||||||
streamname: streamnameBuf,
|
streamname: streamnameBuf,
|
||||||
bpsIndex: uint8(bpsIndex),
|
bpsIndex: 0,
|
||||||
channel: 0,
|
channel: 0,
|
||||||
framecounter: 0,
|
framecounter: make([]byte, 4),
|
||||||
hbuf: bytes.NewBuffer(make([]byte, 0, headerSz)),
|
hbuf: bytes.NewBuffer(make([]byte, headerSz)),
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sr defines the samplerate for the request.
|
// sr defines the samplerate for the request.
|
||||||
@ -75,20 +60,15 @@ func (p *packet) header() []byte {
|
|||||||
p.hbuf.WriteByte(byte(0))
|
p.hbuf.WriteByte(byte(0))
|
||||||
p.hbuf.WriteByte(p.nbc())
|
p.hbuf.WriteByte(p.nbc())
|
||||||
p.hbuf.WriteByte(byte(0x10))
|
p.hbuf.WriteByte(byte(0x10))
|
||||||
p.hbuf.Write(p.streamname[:])
|
p.hbuf.Write(p.streamname)
|
||||||
|
p.hbuf.Write(p.framecounter)
|
||||||
var frameBytes [4]byte
|
|
||||||
binary.LittleEndian.PutUint32(frameBytes[:], p.framecounter)
|
|
||||||
p.hbuf.Write(frameBytes[:])
|
|
||||||
|
|
||||||
return p.hbuf.Bytes()
|
return p.hbuf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// bumpFrameCounter increments the frame counter by 1.
|
// bumpFrameCounter increments the frame counter by 1.
|
||||||
// The uint32 will safely wrap to 0 after reaching max value (4,294,967,295),
|
|
||||||
// which is expected behaviour for network protocol sequence numbers.
|
|
||||||
func (p *packet) bumpFrameCounter() {
|
func (p *packet) bumpFrameCounter() {
|
||||||
p.framecounter++
|
x := binary.LittleEndian.Uint32(p.framecounter)
|
||||||
|
binary.LittleEndian.PutUint32(p.framecounter, x+1)
|
||||||
|
|
||||||
log.Debugf("framecounter: %d", p.framecounter)
|
log.Debugf("framecounter: %d", x)
|
||||||
}
|
}
|
||||||
|
|||||||
23
vbantxt.go
23
vbantxt.go
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
|
// VbanTxt is used to send VBAN-TXT requests to a distant Voicemeeter/Matrix.
|
||||||
type VbanTxt struct {
|
type VbanTxt struct {
|
||||||
conn io.WriteCloser
|
udpConn io.WriteCloser
|
||||||
packet packet
|
packet packet
|
||||||
ratelimit time.Duration
|
ratelimit time.Duration
|
||||||
}
|
}
|
||||||
@ -16,19 +16,14 @@ type VbanTxt struct {
|
|||||||
// New constructs a fully formed VbanTxt instance. This is the package's entry point.
|
// New constructs a fully formed VbanTxt instance. This is the package's entry point.
|
||||||
// It sets default values for it's fields and then runs the option functions.
|
// It sets default values for it's fields and then runs the option functions.
|
||||||
func New(host string, port int, streamname string, options ...Option) (*VbanTxt, error) {
|
func New(host string, port int, streamname string, options ...Option) (*VbanTxt, error) {
|
||||||
conn, err := newUDPConn(host, port)
|
udpConn, err := newUDPConn(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating UDP client for (%s:%d): %w", host, port, err)
|
return nil, fmt.Errorf("error creating UDP client for (%s:%d): %w", host, port, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
packet, err := newPacket(streamname)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error creating packet: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
vt := &VbanTxt{
|
vt := &VbanTxt{
|
||||||
conn: conn,
|
udpConn: udpConn,
|
||||||
packet: packet,
|
packet: newPacket(streamname),
|
||||||
ratelimit: time.Duration(20) * time.Millisecond,
|
ratelimit: time.Duration(20) * time.Millisecond,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,10 +34,10 @@ func New(host string, port int, streamname string, options ...Option) (*VbanTxt,
|
|||||||
return vt, nil
|
return vt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send is responsible for firing each VBAN-TXT request.
|
// Send is resonsible for firing each VBAN-TXT request.
|
||||||
// It waits for {vt.ratelimit} time before returning.
|
// It waits for {vt.ratelimit} time before returning.
|
||||||
func (vt *VbanTxt) Send(cmd string) error {
|
func (vt VbanTxt) Send(cmd string) error {
|
||||||
_, err := vt.conn.Write(append(vt.packet.header(), cmd...))
|
_, err := vt.udpConn.Write(append(vt.packet.header(), []byte(cmd)...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error sending command (%s): %w", cmd, err)
|
return fmt.Errorf("error sending command (%s): %w", cmd, err)
|
||||||
}
|
}
|
||||||
@ -55,8 +50,8 @@ func (vt *VbanTxt) Send(cmd string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close is responsible for closing the UDP Client connection.
|
// Close is responsible for closing the UDP Client connection.
|
||||||
func (vt *VbanTxt) Close() error {
|
func (vt VbanTxt) Close() error {
|
||||||
err := vt.conn.Close()
|
err := vt.udpConn.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error attempting to close UDP Client: %w", err)
|
return fmt.Errorf("error attempting to close UDP Client: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/onyx-and-iris/vbantxt"
|
"github.com/onyx-and-iris/vbantxt"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed testdata/vm.txt
|
//go:embed testdata/vm.txt
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user