forked from AlistGo/alist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
311 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"github.com/Xhofe/alist/conf" | ||
"github.com/allegro/bigcache/v3" | ||
"github.com/eko/gocache/v2/cache" | ||
"github.com/eko/gocache/v2/store" | ||
log "github.com/sirupsen/logrus" | ||
"time" | ||
) | ||
|
||
// InitCache init cache | ||
func InitCache() { | ||
log.Infof("init cache...") | ||
bigCacheConfig := bigcache.DefaultConfig(60 * time.Minute) | ||
bigCacheConfig.HardMaxCacheSize = 512 | ||
bigCacheClient, _ := bigcache.NewBigCache(bigCacheConfig) | ||
bigCacheStore := store.NewBigcache(bigCacheClient, nil) | ||
conf.Cache = cache.New(bigCacheStore) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/Xhofe/alist/conf" | ||
"github.com/Xhofe/alist/utils" | ||
log "github.com/sirupsen/logrus" | ||
"io/ioutil" | ||
) | ||
|
||
// InitConf init config | ||
func InitConf() { | ||
log.Infof("reading config file: %s", conf.ConfigFile) | ||
if !utils.Exists(conf.ConfigFile) { | ||
log.Infof("config file not exists, creating default config file") | ||
conf.Conf = conf.DefaultConfig() | ||
if !utils.WriteToJson(conf.ConfigFile, conf.Conf) { | ||
log.Fatalf("failed to create default config file") | ||
} | ||
return | ||
} | ||
config, err := ioutil.ReadFile(conf.ConfigFile) | ||
if err != nil { | ||
log.Fatalf("reading config file error:%s", err.Error()) | ||
} | ||
conf.Conf = new(conf.Config) | ||
err = json.Unmarshal(config, conf.Conf) | ||
if err != nil { | ||
log.Fatalf("load config error: %s", err.Error()) | ||
} | ||
log.Debugf("config:%+v", conf.Conf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"github.com/Xhofe/alist/conf" | ||
"github.com/robfig/cron/v3" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// InitCron init cron | ||
func InitCron() { | ||
log.Infof("init cron...") | ||
conf.Cron = cron.New() | ||
conf.Cron.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"github.com/Xhofe/alist/conf" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// initLog init log | ||
func InitLog() { | ||
if conf.Debug { | ||
log.SetLevel(log.DebugLevel) | ||
log.SetReportCaller(true) | ||
} | ||
log.SetFormatter(&log.TextFormatter{ | ||
//DisableColors: true, | ||
ForceColors: true, | ||
EnvironmentOverrideColors: true, | ||
TimestampFormat: "2006-01-02 15:04:05", | ||
FullTimestamp: true, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.