alist/alist.go

41 lines
929 B
Go
Raw Normal View History

2021-10-25 10:53:59 +00:00
package main
import (
"flag"
"fmt"
2021-10-27 14:45:36 +00:00
"github.com/Xhofe/alist/bootstrap"
2021-10-25 10:53:59 +00:00
"github.com/Xhofe/alist/conf"
2021-10-26 14:28:37 +00:00
"github.com/Xhofe/alist/public"
"github.com/Xhofe/alist/server"
2021-10-25 10:53:59 +00:00
"github.com/gofiber/fiber/v2"
2021-10-26 14:28:37 +00:00
"github.com/gofiber/fiber/v2/middleware/filesystem"
2021-10-25 10:53:59 +00:00
log "github.com/sirupsen/logrus"
2021-10-26 14:28:37 +00:00
"net/http"
2021-10-25 10:53:59 +00:00
)
2021-10-28 14:50:09 +00:00
func Init() {
2021-10-25 10:53:59 +00:00
flag.StringVar(&conf.ConfigFile, "conf", "config.json", "config file")
flag.BoolVar(&conf.Debug,"debug",false,"start with debug mode")
flag.Parse()
2021-10-27 14:45:36 +00:00
bootstrap.InitLog()
bootstrap.InitConf()
bootstrap.InitCron()
bootstrap.InitModel()
bootstrap.InitCache()
2021-10-25 10:53:59 +00:00
}
func main() {
2021-10-28 14:50:09 +00:00
Init()
2021-10-25 10:53:59 +00:00
app := fiber.New()
2021-10-30 11:26:23 +00:00
server.InitApiRouter(app)
2021-10-26 14:28:37 +00:00
app.Use("/",filesystem.New(filesystem.Config{
Root: http.FS(public.Public),
2021-10-30 11:26:23 +00:00
NotFoundFile: "index.html",
2021-10-26 14:28:37 +00:00
}))
2021-10-25 10:53:59 +00:00
log.Info("starting server")
2021-10-30 11:26:23 +00:00
err := app.Listen(fmt.Sprintf(":%d", conf.Conf.Port))
if err != nil {
log.Errorf("failed to start: %s", err.Error())
}
2021-10-25 10:53:59 +00:00
}