From 688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 25 May 2014 20:11:25 -0400 Subject: Fixed #209 --- modules/base/conf.go | 354 ----------------------------------------------- modules/base/template.go | 10 +- modules/base/tool.go | 8 +- 3 files changed, 11 insertions(+), 361 deletions(-) delete mode 100644 modules/base/conf.go (limited to 'modules/base') diff --git a/modules/base/conf.go b/modules/base/conf.go deleted file mode 100644 index df2bd82722..0000000000 --- a/modules/base/conf.go +++ /dev/null @@ -1,354 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package base - -import ( - "fmt" - "os" - "os/exec" - "path" - "path/filepath" - "strings" - - "github.com/Unknwon/com" - "github.com/Unknwon/goconfig" - qlog "github.com/qiniu/log" - - "github.com/gogits/cache" - "github.com/gogits/session" - - "github.com/gogits/gogs/modules/log" -) - -// Mailer represents mail service. -type Mailer struct { - Name string - Host string - User, Passwd string -} - -type OauthInfo struct { - ClientId, ClientSecret string - Scopes string - AuthUrl, TokenUrl string -} - -// Oauther represents oauth service. -type Oauther struct { - GitHub, Google, Tencent, - Twitter, Weibo bool - OauthInfos map[string]*OauthInfo -} - -var ( - AppVer string - AppName string - AppLogo string - AppUrl string - SshPort int - OfflineMode bool - DisableRouterLog bool - ProdMode bool - Domain string - SecretKey string - RunUser string - - RepoRootPath string - ScriptType string - - InstallLock bool - - LogInRememberDays int - CookieUserName string - CookieRememberName string - - Cfg *goconfig.ConfigFile - MailService *Mailer - OauthService *Oauther - - LogModes []string - LogConfigs []string - - Cache cache.Cache - CacheAdapter string - CacheConfig string - - SessionProvider string - SessionConfig *session.Config - SessionManager *session.Manager - - PictureService string - DisableGravatar bool - - EnableRedis bool - EnableMemcache bool -) - -var Service struct { - RegisterEmailConfirm bool - DisableRegistration bool - RequireSignInView bool - EnableCacheAvatar bool - NotifyMail bool - ActiveCodeLives int - ResetPwdCodeLives int - LdapAuth bool -} - -// ExecDir returns absolute path execution(binary) path. -func ExecDir() (string, error) { - file, err := exec.LookPath(os.Args[0]) - if err != nil { - return "", err - } - p, err := filepath.Abs(file) - if err != nil { - return "", err - } - return path.Dir(strings.Replace(p, "\\", "/", -1)), nil -} - -var logLevels = map[string]string{ - "Trace": "0", - "Debug": "1", - "Info": "2", - "Warn": "3", - "Error": "4", - "Critical": "5", -} - -func newService() { - Service.ActiveCodeLives = Cfg.MustInt("service", "ACTIVE_CODE_LIVE_MINUTES", 180) - Service.ResetPwdCodeLives = Cfg.MustInt("service", "RESET_PASSWD_CODE_LIVE_MINUTES", 180) - Service.DisableRegistration = Cfg.MustBool("service", "DISABLE_REGISTRATION", false) - Service.RequireSignInView = Cfg.MustBool("service", "REQUIRE_SIGNIN_VIEW", false) - Service.EnableCacheAvatar = Cfg.MustBool("service", "ENABLE_CACHE_AVATAR", false) -} - -func newLogService() { - log.Info("%s %s", AppName, AppVer) - - // Get and check log mode. - LogModes = strings.Split(Cfg.MustValue("log", "MODE", "console"), ",") - LogConfigs = make([]string, len(LogModes)) - for i, mode := range LogModes { - mode = strings.TrimSpace(mode) - modeSec := "log." + mode - if _, err := Cfg.GetSection(modeSec); err != nil { - qlog.Fatalf("Unknown log mode: %s\n", mode) - } - - // Log level. - levelName := Cfg.MustValueRange("log."+mode, "LEVEL", "Trace", - []string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"}) - level, ok := logLevels[levelName] - if !ok { - qlog.Fatalf("Unknown log level: %s\n", levelName) - } - - // Generate log configuration. - switch mode { - case "console": - LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level) - case "file": - logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log") - os.MkdirAll(path.Dir(logPath), os.ModePerm) - LogConfigs[i] = fmt.Sprintf( - `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level, - logPath, - Cfg.MustBool(modeSec, "LOG_ROTATE", true), - Cfg.MustInt(modeSec, "MAX_LINES", 1000000), - 1<