mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 10:17:17 +08:00
feat: 重命名主体项目
This commit is contained in:
75
internal/app/ace.go
Normal file
75
internal/app/ace.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gookit/validate"
|
||||
"github.com/knadh/koanf/v2"
|
||||
"github.com/robfig/cron/v3"
|
||||
|
||||
"github.com/tnborg/panel/pkg/queue"
|
||||
)
|
||||
|
||||
type Ace struct {
|
||||
conf *koanf.Koanf
|
||||
router *fiber.App
|
||||
migrator *gormigrate.Gormigrate
|
||||
cron *cron.Cron
|
||||
queue *queue.Queue
|
||||
}
|
||||
|
||||
func NewWeb(conf *koanf.Koanf, router *fiber.App, migrator *gormigrate.Gormigrate, cron *cron.Cron, queue *queue.Queue, _ *validate.Validation) *Ace {
|
||||
return &Ace{
|
||||
conf: conf,
|
||||
router: router,
|
||||
migrator: migrator,
|
||||
cron: cron,
|
||||
queue: queue,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Ace) Run() error {
|
||||
// migrate database
|
||||
if err := r.migrator.Migrate(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("[DB] database migrated")
|
||||
|
||||
// start cron scheduler
|
||||
r.cron.Start()
|
||||
fmt.Println("[CRON] cron scheduler started")
|
||||
|
||||
// start queue
|
||||
r.queue.Run(context.TODO())
|
||||
|
||||
// run http server
|
||||
config := fiber.ListenConfig{
|
||||
ListenerNetwork: fiber.NetworkTCP,
|
||||
EnablePrefork: r.conf.Bool("http.prefork"),
|
||||
EnablePrintRoutes: r.conf.Bool("http.debug"),
|
||||
DisableStartupMessage: !r.conf.Bool("http.debug"),
|
||||
}
|
||||
if r.conf.Bool("http.tls") {
|
||||
config.CertFile = filepath.Join(Root, "panel/storage/cert.pem")
|
||||
config.CertKeyFile = filepath.Join(Root, "panel/storage/cert.key")
|
||||
fmt.Println("[HTTP] listening and serving on port", r.conf.MustInt("http.port"), "with tls")
|
||||
} else {
|
||||
fmt.Println("[HTTP] listening and serving on port", r.conf.MustInt("http.port"))
|
||||
}
|
||||
|
||||
return r.router.Listen(fmt.Sprintf(":%d", r.conf.MustInt("http.port")), config)
|
||||
}
|
||||
|
||||
func (r *Ace) listenConfig() fiber.ListenConfig {
|
||||
// prefork not support dual stack
|
||||
return fiber.ListenConfig{
|
||||
ListenerNetwork: fiber.NetworkTCP,
|
||||
EnablePrefork: r.conf.Bool("http.prefork"),
|
||||
EnablePrintRoutes: r.conf.Bool("http.debug"),
|
||||
DisableStartupMessage: !r.conf.Bool("http.debug"),
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/bddjr/hlfhr"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"github.com/gookit/validate"
|
||||
"github.com/knadh/koanf/v2"
|
||||
"github.com/robfig/cron/v3"
|
||||
|
||||
"github.com/tnborg/panel/pkg/queue"
|
||||
)
|
||||
|
||||
type Web struct {
|
||||
conf *koanf.Koanf
|
||||
router *chi.Mux
|
||||
server *hlfhr.Server
|
||||
migrator *gormigrate.Gormigrate
|
||||
cron *cron.Cron
|
||||
queue *queue.Queue
|
||||
}
|
||||
|
||||
func NewWeb(conf *koanf.Koanf, router *chi.Mux, server *hlfhr.Server, migrator *gormigrate.Gormigrate, cron *cron.Cron, queue *queue.Queue, _ *validate.Validation) *Web {
|
||||
return &Web{
|
||||
conf: conf,
|
||||
router: router,
|
||||
server: server,
|
||||
migrator: migrator,
|
||||
cron: cron,
|
||||
queue: queue,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Web) Run() error {
|
||||
// migrate database
|
||||
if err := r.migrator.Migrate(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("[DB] database migrated")
|
||||
|
||||
// start cron scheduler
|
||||
r.cron.Start()
|
||||
fmt.Println("[CRON] cron scheduler started")
|
||||
|
||||
// start queue
|
||||
r.queue.Run(context.TODO())
|
||||
|
||||
// run http server
|
||||
if r.conf.Bool("http.tls") {
|
||||
cert := filepath.Join(Root, "panel/storage/cert.pem")
|
||||
key := filepath.Join(Root, "panel/storage/cert.key")
|
||||
fmt.Println("[HTTP] listening and serving on port", r.conf.MustInt("http.port"), "with tls")
|
||||
if err := r.server.ListenAndServeTLS(cert, key); !errors.Is(err, http.ErrServerClosed) {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
fmt.Println("[HTTP] listening and serving on port", r.conf.MustInt("http.port"))
|
||||
if err := r.server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user