diff options
author | skyblue <ssx205@gmail.com> | 2014-03-21 23:36:01 +0800 |
---|---|---|
committer | skyblue <ssx205@gmail.com> | 2014-03-21 23:36:01 +0800 |
commit | 9a9ae918c527fb04a1f181ad6f967d5969b93c15 (patch) | |
tree | 789d624fcc6949940ae1621bd0fe051578363efc /modules/base/conf.go | |
parent | d725c41b56e072122faf539d5a14d36c18f5c312 (diff) | |
parent | 9218f76c8e4a6fafbe6bed1d61eb66ba73bf70f2 (diff) |
Merge branch 'master' of github.com:gogits/gogs
Diffstat (limited to 'modules/base/conf.go')
-rw-r--r-- | modules/base/conf.go | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/modules/base/conf.go b/modules/base/conf.go index 3962972c..2c3ecd72 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -133,6 +133,30 @@ func newLogService() { log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName) } +func newCacheService() { + CacheAdapter = Cfg.MustValue("cache", "ADAPTER", "memory") + + switch CacheAdapter { + case "memory": + CacheConfig = fmt.Sprintf(`{"interval":%d}`, Cfg.MustInt("cache", "INTERVAL", 60)) + case "redis", "memcache": + CacheConfig = fmt.Sprintf(`{"conn":"%s"}`, Cfg.MustValue("cache", "HOST")) + default: + fmt.Printf("Unknown cache adapter: %s\n", CacheAdapter) + os.Exit(2) + } + + var err error + Cache, err = cache.NewCache(CacheAdapter, CacheConfig) + if err != nil { + fmt.Printf("Init cache system failed, adapter: %s, config: %s, %v\n", + CacheAdapter, CacheConfig, err) + os.Exit(2) + } + + log.Info("Cache Service Enabled") +} + func newMailService() { // Check mailer setting. if Cfg.MustBool("mailer", "ENABLED") { @@ -188,16 +212,6 @@ func NewConfigContext() { SecretKey = Cfg.MustValue("security", "SECRET_KEY") RunUser = Cfg.MustValue("", "RUN_USER") - CacheAdapter = Cfg.MustValue("cache", "ADAPTER") - CacheConfig = Cfg.MustValue("cache", "CONFIG") - - Cache, err = cache.NewCache(CacheAdapter, CacheConfig) - if err != nil { - fmt.Printf("Init cache system failed, adapter: %s, config: %s, %v\n", - CacheAdapter, CacheConfig, err) - os.Exit(2) - } - // Determine and create root git reposiroty path. RepoRootPath = Cfg.MustValue("repository", "ROOT") if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil { @@ -209,6 +223,7 @@ func NewConfigContext() { func NewServices() { newService() newLogService() + newCacheService() newMailService() newRegisterMailService() } |