email/client.go

45 lines
623 B
Go

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
}