Add custom.ini

This commit is contained in:
Unknown 2014-03-10 23:03:17 -04:00
parent 52837e3d36
commit 6ce9d800d0
4 changed files with 14 additions and 18 deletions

3
.gitignore vendored
View File

@ -3,4 +3,5 @@ gogs
*.exe~ *.exe~
.DS_Store .DS_Store
*.db *.db
*.log *.log
conf/custom.ini

View File

@ -3,7 +3,6 @@ RUN_USER = lunny
[repository] [repository]
ROOT = /Users/lunny/git/gogs-repositories ROOT = /Users/lunny/git/gogs-repositories
ROOT_jiahuachen = /Users/jiahuachen/git/gogs-repositories
[server] [server]
HTTP_ADDR = HTTP_ADDR =
@ -15,7 +14,6 @@ HOST =
NAME = gogs NAME = gogs
USER = root USER = root
PASSWD = PASSWD =
PASSWD_jiahua = root
[security] [security]
USER_PASSWD_SALT = !#@FDEWREWR&*( USER_PASSWD_SALT = !#@FDEWREWR&*(

View File

@ -7,7 +7,6 @@ package models
import ( import (
"fmt" "fmt"
"os" "os"
"os/user"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm" "github.com/lunny/xorm"
@ -47,16 +46,7 @@ func setEngine() {
dbUser := base.Cfg.MustValue("database", "USER") dbUser := base.Cfg.MustValue("database", "USER")
dbPwd := base.Cfg.MustValue("database", "PASSWD") dbPwd := base.Cfg.MustValue("database", "PASSWD")
uname, err := user.Current() var err error
if err != nil {
fmt.Printf("models.init -> fail to get user: %s\n", err)
os.Exit(2)
}
if uname.Username == "jiahuachen" {
dbPwd = base.Cfg.MustValue("database", "PASSWD_jiahua")
}
switch dbType { switch dbType {
case "mysql": case "mysql":
orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%v:%v@%v/%v?charset=utf8", orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%v:%v@%v/%v?charset=utf8",
@ -83,9 +73,6 @@ func setEngine() {
//log.Trace("Initialized database -> %s", dbName) //log.Trace("Initialized database -> %s", dbName)
RepoRootPath = base.Cfg.MustValue("repository", "ROOT") RepoRootPath = base.Cfg.MustValue("repository", "ROOT")
if uname.Username == "jiahuachen" {
RepoRootPath = base.Cfg.MustValue("repository", "ROOT_jiahuachen")
}
} }
func init() { func init() {

View File

@ -11,6 +11,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"github.com/Unknwon/com"
"github.com/Unknwon/goconfig" "github.com/Unknwon/goconfig"
) )
@ -36,11 +37,20 @@ func init() {
os.Exit(2) os.Exit(2)
} }
cfgPath := filepath.Join(workDir, "conf", "app.ini") cfgPathPrefix := filepath.Join(workDir, "conf")
cfgPath := filepath.Join(cfgPathPrefix, "app.ini")
Cfg, err = goconfig.LoadConfigFile(cfgPath) Cfg, err = goconfig.LoadConfigFile(cfgPath)
if err != nil { if err != nil {
fmt.Printf("Cannot load config file '%s'\n", cfgPath) fmt.Printf("Cannot load config file '%s'\n", cfgPath)
os.Exit(2) os.Exit(2)
} }
cfgPath = filepath.Join(cfgPathPrefix, "custom.ini")
if com.IsFile(cfgPath) {
if err = Cfg.AppendFiles(cfgPath); err != nil {
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
os.Exit(2)
}
}
Cfg.BlockMode = false Cfg.BlockMode = false
} }