email/client.go

45 lines
623 B
Go
Raw Permalink Normal View History

2022-11-23 02:50:34 +00:00
package email
import (
"errors"
"fmt"
"git.selly.red/Selly-Modules/natsio"
)
var (
c *Client
server natsio.Server
js natsio.JetStream
)
// GetClient ...
func GetClient() *Client {
return c
}
// Config ...
type Config struct {
Nats natsio.Config
}
// Client ...
type Client struct {
Config Config
}
// NewClient ...
func NewClient(cfg Config) (*Client, error) {
if cfg.Nats.URL == "" {
return nil, errors.New("nats url is required")
}
if err := natsio.Connect(cfg.Nats); err != nil {
return nil, fmt.Errorf("nats connect failed: %v", err)
}
c = &Client{
Config: cfg,
}
return c, nil
}