upp/upp.go

56 lines
896 B
Go
Raw Normal View History

2024-12-30 15:09:02 +08:00
package upp
import (
"context"
"sync"
"github.com/elastic/go-elasticsearch/v7"
"github.com/loveuer/upp/pkg/api"
"github.com/loveuer/upp/pkg/cache"
"github.com/loveuer/upp/pkg/interfaces"
2025-01-01 21:01:05 -08:00
"github.com/loveuer/upp/pkg/log"
2024-12-30 15:09:02 +08:00
"gorm.io/gorm"
)
type uppApi struct {
engine *api.App
config ApiConfig
}
type upp struct {
debug bool
ctx context.Context
logger *sync.Pool
db *gorm.DB
cache cache.Cache
es *elasticsearch.Client
api *uppApi
initFns []func(interfaces.Upp)
taskCh []<-chan func(interfaces.Upp) error
}
func (u *upp) With(modules ...module) {
for _, m := range modules {
m(u)
}
}
2025-01-01 21:01:05 -08:00
func New(configs ...Config) *upp {
config := Config{}
2024-12-30 15:09:02 +08:00
2025-01-01 21:01:05 -08:00
if len(configs) > 0 {
config = configs[0]
2024-12-30 15:09:02 +08:00
}
2025-01-01 21:01:05 -08:00
if config.Debug || _flag.debug {
log.SetLogLevel(log.LogLevelDebug)
2024-12-30 15:09:02 +08:00
}
app := &upp{
logger: upp_logger_pool,
2025-01-01 21:01:05 -08:00
debug: config.Debug,
2024-12-30 15:09:02 +08:00
}
return app
}