refactor: Update NATS subscription logic and configuration

The code changes in `main.go` update the NATS subscription logic and configuration. The `Subscribe` function now uses the `NatsHandler` struct to handle the subscription. The `NewNatsHandler` function is added to create a new instance of the `NatsHandler` with the provided configuration. The configuration values are passed to the `NatsSubscriber` constructor to set up the NATS subscription. This refactor improves the modularity and readability of the NATS subscription code.
This commit is contained in:
windyboy
2024-07-21 23:09:29 +08:00
parent 29fecbbe6c
commit 24c9beeb13
3 changed files with 95 additions and 12 deletions
+5 -4
View File
@@ -5,6 +5,7 @@ import (
"os"
"regexp"
"strings"
"time"
"github.com/spf13/viper"
)
@@ -29,10 +30,10 @@ type SubscriptionConfig struct {
}
type TimeoutsConfig struct {
ServerTimeout string `mapstructure:"server_timeout"`
ReconnectWait string `mapstructure:"reconnect_wait"`
CloseTimeout string `mapstructure:"close_timeout"`
AckWaitTimeout string `mapstructure:"ack_wait_timeout"`
ServerTimeout time.Duration `mapstructure:"server_timeout"`
ReconnectWait time.Duration `mapstructure:"reconnect_wait"`
CloseTimeout time.Duration `mapstructure:"close_timeout"`
AckWaitTimeout time.Duration `mapstructure:"ack_wait_timeout"`
}
type BodyConfig struct {