init project
This commit is contained in:
1 parent
d63cc8d9f5
commit
ee07869839
39 files changed
+1560
-622
No files matched your search
+18
-35
@@ -1,68 +1,51 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"git.xiaotuo.co/micro/skeleton/internal/storage"
|
||||
"github.com/nats-io/nats.go"
|
||||
"micro_layout/internal/storage"
|
||||
)
|
||||
|
||||
var Resources *resources
|
||||
|
||||
type resources struct {
|
||||
Env string
|
||||
Server string
|
||||
Storage *storage.Storage
|
||||
JetStreamBroker nats.JetStreamContext
|
||||
|
||||
MessageLogic MessageLogic
|
||||
MessageLogic MessageLogic
|
||||
UserLogic *UserLogic
|
||||
}
|
||||
|
||||
func Init(opts ...Option) error {
|
||||
options := &Options{}
|
||||
for _, o := range opts {
|
||||
o(options)
|
||||
for _, option := range opts {
|
||||
option(options)
|
||||
}
|
||||
|
||||
Resources = &resources{
|
||||
Env: options.env,
|
||||
Server: options.server,
|
||||
|
||||
JetStreamBroker: options.jetStreamBr,
|
||||
Env: options.env,
|
||||
Storage: options.storage,
|
||||
JetStreamBroker: options.jetStream,
|
||||
MessageLogic: newMessageLogic(),
|
||||
UserLogic: newUserLogic(),
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type Option func(o *Options)
|
||||
type Option func(*Options)
|
||||
|
||||
type Options struct {
|
||||
env string
|
||||
server string
|
||||
etcdServer string
|
||||
st *storage.Storage
|
||||
jetStreamBr nats.JetStreamContext
|
||||
tiktokAuthGateway string
|
||||
env string
|
||||
storage *storage.Storage
|
||||
jetStream nats.JetStreamContext
|
||||
}
|
||||
|
||||
func WithEnv(env string) Option {
|
||||
return func(o *Options) {
|
||||
o.env = env
|
||||
}
|
||||
return func(options *Options) { options.env = env }
|
||||
}
|
||||
|
||||
func WithStorage(st *storage.Storage) Option {
|
||||
return func(o *Options) {
|
||||
o.st = st
|
||||
}
|
||||
return func(options *Options) { options.storage = st }
|
||||
}
|
||||
|
||||
func WithEtcdServer(etcdServer string) Option {
|
||||
return func(o *Options) {
|
||||
o.etcdServer = etcdServer
|
||||
}
|
||||
}
|
||||
|
||||
func WithJetStreamBroker(br nats.JetStreamContext) Option {
|
||||
return func(o *Options) {
|
||||
o.jetStreamBr = br
|
||||
}
|
||||
func WithJetStreamBroker(broker nats.JetStreamContext) Option {
|
||||
return func(options *Options) { options.jetStream = broker }
|
||||
}
|
||||
Reference in new issue
Block a user