upp/uzone.go
2025-03-10 22:41:10 +08:00

74 lines
1.2 KiB
Go

package uzone
import (
"context"
"sync"
"github.com/elastic/go-elasticsearch/v7"
"github.com/loveuer/uzone/pkg/api"
"github.com/loveuer/uzone/pkg/cache"
"github.com/loveuer/uzone/pkg/interfaces"
"github.com/loveuer/uzone/pkg/log"
"gorm.io/gorm"
)
const Banner = `
__ ______
/ / / /_ / ___ ___ ___
/ /_/ / / /_/ _ \/ _ \/ -_)
\____/ /___/\___/_//_/\__/
`
type uzoneApi struct {
engine *api.App
config ApiConfig
}
type uzone struct {
debug bool
ctx context.Context
logger *sync.Pool
db *gorm.DB
cache cache.Cache
es *elasticsearch.Client
api *uzoneApi
initFns struct {
_sync []func(interfaces.Uzone)
_async []func(interfaces.Uzone)
}
taskCh []<-chan func(interfaces.Uzone) error
}
func (u *uzone) With(modules ...module) {
for _, m := range modules {
m(u)
}
}
func New(configs ...Config) *uzone {
config := Config{}
if len(configs) > 0 {
config = configs[0]
}
app := &uzone{
logger: uzone_logger_pool,
initFns: struct {
_sync []func(interfaces.Uzone)
_async []func(interfaces.Uzone)
}{
_sync: make([]func(interfaces.Uzone), 0),
_async: make([]func(interfaces.Uzone), 0),
},
}
if config.Debug || property.Debug {
log.Debug()
app.debug = true
}
return app
}