alist/alist.go

61 lines
1.3 KiB
Go
Raw Normal View History

2021-10-25 10:53:59 +00:00
package main
import (
"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-12-06 07:55:05 +00:00
_ "github.com/Xhofe/alist/drivers"
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-16 07:00:56 +00:00
func Init() bool {
2021-12-06 07:55:05 +00:00
//bootstrap.InitLog()
2021-10-27 14:45:36 +00:00
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
}
2022-02-04 06:58:48 +00:00
fmt.Printf("your password: %s\n", pass.Value)
2021-11-16 07:00:56 +00:00
return false
}
2021-12-20 16:32:09 +00:00
server.InitIndex()
2021-11-16 07:00:56 +00:00
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 {
2022-02-20 07:14:18 +00:00
fmt.Printf("Built At: %s\nGo Version: %s\nAuthor: %s\nCommit ID: %s\nVersion: %s\nWebVersion: %s\n",
conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.GitTag, conf.WebTag)
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
2021-12-30 12:42:37 +00:00
if conf.Conf.Scheme.Https {
err = r.RunTLS(base, conf.Conf.Scheme.CertFile, conf.Conf.Scheme.KeyFile)
2021-11-30 16:19:06 +00:00
} 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
}