alist/alist.go

67 lines
1.6 KiB
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-11-16 07:00:56 +00:00
"github.com/Xhofe/alist/model"
2021-10-26 14:28:37 +00:00
"github.com/Xhofe/alist/server"
2021-11-13 07:53:26 +00:00
"github.com/gin-gonic/gin"
2021-10-25 10:53:59 +00:00
log "github.com/sirupsen/logrus"
)
2021-11-03 11:51:19 +00:00
func init() {
2021-11-13 06:23:41 +00:00
flag.StringVar(&conf.ConfigFile, "conf", "data/config.json", "config file")
2021-11-03 11:51:19 +00:00
flag.BoolVar(&conf.Debug, "debug", false, "start with debug mode")
flag.BoolVar(&conf.Version, "version", false, "print version info")
2021-11-16 07:00:56 +00:00
flag.BoolVar(&conf.Password, "password", false, "print current password")
2021-10-25 10:53:59 +00:00
flag.Parse()
2021-11-03 11:51:19 +00:00
}
2021-11-16 07:00:56 +00:00
func Init() bool {
2021-10-27 14:45:36 +00:00
bootstrap.InitLog()
bootstrap.InitConf()
bootstrap.InitCron()
bootstrap.InitModel()
2021-11-16 07:00:56 +00:00
if conf.Password {
pass, err := model.GetSettingByKey("password")
if err != nil {
log.Errorf(err.Error())
return false
}
log.Infof("current password: %s", pass.Value)
return false
}
bootstrap.InitSettings()
bootstrap.InitAccounts()
2021-10-27 14:45:36 +00:00
bootstrap.InitCache()
2021-11-16 07:00:56 +00:00
return true
2021-10-25 10:53:59 +00:00
}
func main() {
2021-11-03 11:51:19 +00:00
if conf.Version {
2021-11-05 11:03:54 +00:00
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)
2021-11-03 11:51:19 +00:00
return
}
2021-11-16 07:00:56 +00:00
if !Init() {
return
}
2021-11-13 07:53:26 +00:00
if !conf.Debug {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()
server.InitApiRouter(r)
2021-11-26 12:20:32 +00:00
base := fmt.Sprintf("%s:%d", conf.Conf.Address, conf.Conf.Port)
2021-11-26 12:23:33 +00:00
log.Infof("start server @ %s", base)
2021-11-30 16:19:06 +00:00
var err error
if conf.Conf.Https {
err = r.RunTLS(base, conf.Conf.CertFile, conf.Conf.KeyFile)
} else {
err = r.Run(base)
}
2021-10-30 11:26:23 +00:00
if err != nil {
log.Errorf("failed to start: %s", err.Error())
}
2021-10-25 10:53:59 +00:00
}