52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package logic
|
|
|
|
import (
|
|
"github.com/nats-io/nats.go"
|
|
"micro_layout/internal/storage"
|
|
)
|
|
|
|
var Resources *resources
|
|
|
|
type resources struct {
|
|
Env string
|
|
Storage *storage.Storage
|
|
JetStreamBroker nats.JetStreamContext
|
|
MessageLogic MessageLogic
|
|
UserLogic *UserLogic
|
|
}
|
|
|
|
func Init(opts ...Option) error {
|
|
options := &Options{}
|
|
for _, option := range opts {
|
|
option(options)
|
|
}
|
|
Resources = &resources{
|
|
Env: options.env,
|
|
Storage: options.storage,
|
|
JetStreamBroker: options.jetStream,
|
|
MessageLogic: newMessageLogic(),
|
|
UserLogic: newUserLogic(),
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type Option func(*Options)
|
|
|
|
type Options struct {
|
|
env string
|
|
storage *storage.Storage
|
|
jetStream nats.JetStreamContext
|
|
}
|
|
|
|
func WithEnv(env string) Option {
|
|
return func(options *Options) { options.env = env }
|
|
}
|
|
|
|
func WithStorage(st *storage.Storage) Option {
|
|
return func(options *Options) { options.storage = st }
|
|
}
|
|
|
|
func WithJetStreamBroker(broker nats.JetStreamContext) Option {
|
|
return func(options *Options) { options.jetStream = broker }
|
|
}
|