refactor: Update nats subscription handling

The code changes in `sub.go` update the handling of NATS subscriptions. The `Subscribe` function now takes in a `config` parameter, allowing for more flexibility in configuring the subscription. Additionally, the `Subscribe` function now uses the `handler` and `marshaler` parameters to handle incoming messages and marshal/unmarshal data, respectively. These changes improve the modularity and extensibility of the code when working with NATS subscriptions.
This commit is contained in:
windyboy
2024-07-30 10:25:59 +08:00
parent ebcca5c1ec
commit 766925f7f9
3 changed files with 86 additions and 74 deletions
+4 -2
View File
@@ -2,6 +2,7 @@ package main
import (
"caatsm/internal/config"
"caatsm/internal/handlers"
"caatsm/internal/nats"
"caatsm/pkg/utils"
@@ -24,6 +25,7 @@ func main() {
fmt.Println("Loaded configuration successfully")
log.Info("Starting nats subscriber")
subscribe := nats.NewNatsHandler(cfg)
subscribe.Subscribe()
handler := handlers.NewNatsHandler(cfg)
nats.Subscribe(cfg, &handlers.PlainTextMarshaler{}, handler)
}