forked from AlistGo/alist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalist.go
48 lines (44 loc) · 1.18 KB
/
alist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"flag"
"fmt"
"github.com/Xhofe/alist/bootstrap"
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/public"
"github.com/Xhofe/alist/server"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
log "github.com/sirupsen/logrus"
"net/http"
)
func init() {
flag.StringVar(&conf.ConfigFile, "conf", "config.json", "config file")
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
flag.BoolVar(&conf.Version, "version", false, "print version info")
flag.Parse()
}
func Init() {
bootstrap.InitLog()
bootstrap.InitConf()
bootstrap.InitCron()
bootstrap.InitModel()
bootstrap.InitCache()
}
func main() {
if conf.Version {
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion: %s\n", conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag)
return
}
Init()
app := fiber.New()
server.InitApiRouter(app)
app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(public.Public),
NotFoundFile: "index.html",
}))
log.Info("starting server")
err := app.Listen(fmt.Sprintf(":%d", conf.Conf.Port))
if err != nil {
log.Errorf("failed to start: %s", err.Error())
}
}