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:
w1ndyb0y
2026-07-10 15:32:34 +08:00
parent 5f3334ec87
commit 419f25f0dd
20 changed files with 1519 additions and 206 deletions
+31 -23
View File
@@ -65,30 +65,38 @@ func InitDb(file string, init bool) error {
return nil
}
func InsertTelegram(teleString string) {
if Tcp {
getWriteLock()
db := getDb()
defer db.Close()
var insertSQL string
if ClientReady && WriteToClient(teleString) == nil {
insertSQL = InsertOld
} else {
insertSQL = InsertNew
}
stmt, _ := db.Prepare(insertSQL)
defer stmt.Close()
result, err := stmt.Exec(teleString)
id, _ := result.LastInsertId()
checkDbErr(err, "error in insert telegram ")
isWriting = false
if insertSQL == InsertOld {
Log.Info("telegram processed ", zap.Int64("id", id))
} else {
Log.Info("telegram saved ", zap.Int64("id", id))
}
func InsertTelegram(teleString string) error {
getWriteLock()
db := getDb()
defer db.Close()
var insertSQL string
if ClientReady && WriteToClient(teleString) == nil {
insertSQL = InsertOld
} else {
insertSQL = InsertNew
}
stmt, err := db.Prepare(insertSQL)
if err != nil {
isWriting = false
Log.Error("error in prepare insert telegram ", zap.Error(err))
return err
}
defer stmt.Close()
result, err := stmt.Exec(teleString)
if err != nil {
isWriting = false
Log.Error("error in insert telegram ", zap.Error(err))
return err
}
id, _ := result.LastInsertId()
isWriting = false
if insertSQL == InsertOld {
Log.Info("telegram processed ", zap.Int64("id", id))
} else {
Log.Info("telegram saved ", zap.Int64("id", id))
}
return nil
}
func LoadUnprocessed() {