fix: comprehensive bug fixes and architecture restructuring
Phase 1 — Bug fixes (7 bugs): - Bug 1: Pulsar mode data loss — always persist to SQLite regardless of mode - Bug 2: PulsarSend closing TCP client — use independent resetPulsarProducer() - Bug 3: Greedy regex — use non-greedy (?s)ZCZC.*?NNNN - Bug 4: Data after NNNN discarded — keep remaining buffer data - Bug 5: strings.Index > 0 boundary — use strings.Contains - Bug 6: Variable shadowing in PulsarSend — use = not := - Bug 7: Accept failure nil panic — add continue + retry logic Phase 2 — Architecture restructuring: - Split utils/ into config/, serial/, telegram/, storage/, transport/ - Define Sender, Repository, Reader interfaces - Introduce app/ layer with context.Context lifecycle - Replace spinlock with sync.Mutex - Unified Config struct replaces 15+ global vars Phase 3 — Testing & tooling: - telegram/parser_test.go (7 test cases) - storage/store_test.go (5 test cases) - transport/transport_test.go (4 test cases) - Taskfile: add test, test-race, test-cover tasks - Go version: 1.15 -> 1.21
This commit is contained in:
+150
@@ -0,0 +1,150 @@
|
||||
# https://taskfile.dev
|
||||
version: "3"
|
||||
|
||||
vars:
|
||||
APP: tele-recv
|
||||
BIN_DIR: bin
|
||||
CONFIG: telegram.yaml
|
||||
GO_VERSION: "1.15"
|
||||
LDFLAGS: '-s -w'
|
||||
BUILD_DIR: "{{.BIN_DIR}}/{{.APP}}"
|
||||
|
||||
tasks:
|
||||
default:
|
||||
desc: Show available tasks
|
||||
cmd: task --list-all
|
||||
|
||||
# ─── Build ────────────────────────────────────────────────────────────────────
|
||||
|
||||
build:
|
||||
desc: Build the binary for the current platform
|
||||
deps: [deps]
|
||||
cmds:
|
||||
- mkdir -p "{{.BIN_DIR}}"
|
||||
- CGO_ENABLED=1 go build -ldflags="{{.LDFLAGS}}" -o "{{.BIN_DIR}}/{{.APP}}" .
|
||||
sources:
|
||||
- "**/*.go"
|
||||
- go.mod
|
||||
- go.sum
|
||||
generates:
|
||||
- "{{.BIN_DIR}}/{{.APP}}"
|
||||
|
||||
build-all:
|
||||
desc: Cross-compile for linux/amd64 and windows/amd64
|
||||
cmds:
|
||||
- task: build-linux
|
||||
- task: build-windows
|
||||
|
||||
build-linux:
|
||||
desc: Build for linux/amd64 (requires CGO cross-compiler)
|
||||
env:
|
||||
GOOS: linux
|
||||
GOARCH: amd64
|
||||
CGO_ENABLED: "1"
|
||||
CC: x86_64-linux-gnu-gcc
|
||||
cmds:
|
||||
- mkdir -p "{{.BIN_DIR}}"
|
||||
- go build -ldflags="{{.LDFLAGS}}" -o "{{.BIN_DIR}}/{{.APP}}-linux" .
|
||||
sources:
|
||||
- "**/*.go"
|
||||
- go.mod
|
||||
- go.sum
|
||||
generates:
|
||||
- "{{.BIN_DIR}}/{{.APP}}-linux"
|
||||
silent: false
|
||||
|
||||
build-windows:
|
||||
desc: Build for windows/amd64 (requires MinGW cross-compiler)
|
||||
env:
|
||||
GOOS: windows
|
||||
GOARCH: amd64
|
||||
CGO_ENABLED: "1"
|
||||
CC: x86_64-w64-mingw32-gcc
|
||||
cmds:
|
||||
- mkdir -p "{{.BIN_DIR}}"
|
||||
- go build -ldflags="{{.LDFLAGS}}" -o "{{.BIN_DIR}}/{{.APP}}-win64.exe" .
|
||||
sources:
|
||||
- "**/*.go"
|
||||
- go.mod
|
||||
- go.sum
|
||||
generates:
|
||||
- "{{.BIN_DIR}}/{{.APP}}-win64.exe"
|
||||
silent: false
|
||||
|
||||
# ─── Test ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
test:
|
||||
desc: Run all tests
|
||||
cmds:
|
||||
- go test ./...
|
||||
|
||||
test-race:
|
||||
desc: Run tests with race detector
|
||||
cmds:
|
||||
- go test -race ./...
|
||||
|
||||
test-cover:
|
||||
desc: Run tests with coverage report
|
||||
cmds:
|
||||
- go test -coverprofile=coverage.out ./...
|
||||
- go tool cover -func=coverage.out
|
||||
|
||||
# ─── Run ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
run:
|
||||
desc: Run the service (start subcommand)
|
||||
deps: [build]
|
||||
cmds:
|
||||
- "{{.BIN_DIR}}/{{.APP}} start"
|
||||
|
||||
run-test:
|
||||
desc: Run the environment test (test subcommand)
|
||||
deps: [build]
|
||||
cmds:
|
||||
- "{{.BIN_DIR}}/{{.APP}} test"
|
||||
|
||||
# ─── Development helpers ──────────────────────────────────────────────────────
|
||||
|
||||
emu:
|
||||
desc: Create a virtual serial port pair (ttyS0 ↔ ttyS1) with socat
|
||||
cmds:
|
||||
- socat PTY,link=ttyS0 PTY,link=ttyS1
|
||||
silent: false
|
||||
|
||||
deps:
|
||||
desc: Tidy and download Go module dependencies
|
||||
cmds:
|
||||
- go mod tidy
|
||||
- go mod download
|
||||
sources:
|
||||
- go.mod
|
||||
- go.sum
|
||||
generates:
|
||||
- go.sum
|
||||
|
||||
lint:
|
||||
desc: Run go vet on all packages
|
||||
cmds:
|
||||
- go vet ./...
|
||||
|
||||
clean:
|
||||
desc: Remove build artifacts, logs, and database
|
||||
cmds:
|
||||
- rm -rf "{{.BIN_DIR}}"
|
||||
- rm -f telegram.db
|
||||
- rm -rf ./logs/
|
||||
silent: false
|
||||
|
||||
# ─── Distribution package ─────────────────────────────────────────────────────
|
||||
|
||||
dist:
|
||||
desc: Build all platforms and package into a tarball
|
||||
cmds:
|
||||
- task: build-all
|
||||
- mkdir -p "{{.BUILD_DIR}}"
|
||||
- cp "{{.BIN_DIR}}/{{.APP}}-linux" "{{.BUILD_DIR}}/"
|
||||
- cp "{{.BIN_DIR}}/{{.APP}}-win64.exe" "{{.BUILD_DIR}}/"
|
||||
- cp "{{.CONFIG}}" "{{.BUILD_DIR}}/"
|
||||
- cd "{{.BIN_DIR}}" && tar czvf "{{.APP}}.tar.gz" "{{.APP}}/" && mv "{{.APP}}.tar.gz" .
|
||||
- rm -rf "{{.BUILD_DIR}}"
|
||||
silent: false
|
||||
Reference in New Issue
Block a user