]> source.dussan.org Git - gitea.git/commitdiff
Merge utils to modules
authorUnknown <joe2010xtmf@163.com>
Fri, 7 Mar 2014 22:22:15 +0000 (17:22 -0500)
committerUnknown <joe2010xtmf@163.com>
Fri, 7 Mar 2014 22:22:15 +0000 (17:22 -0500)
17 files changed:
bee.json
gogs.go
models/models.go
models/repo.go
models/user.go
modules/auth/form.go
modules/auth/user.go
modules/base/conf.go [new file with mode: 0644]
modules/base/tool.go [new file with mode: 0644]
modules/log/log.go [new file with mode: 0644]
routers/repo/repo.go
routers/user/ssh.go
routers/user/user.go
utils/conf.go [deleted file]
utils/log/log.go [deleted file]
utils/tool.go [deleted file]
web.go

index e4a0f803d3b3434dc9af8cb4d46d26d0b63459b9..de211f7277ee257caa065ebab84fd6e871171ab7 100644 (file)
--- a/bee.json
+++ b/bee.json
@@ -11,7 +11,7 @@
                "controllers": "routers",
                "models": "",
                "others": [
-                       "utils", "modules",
+                       "modules",
                        "$GOPATH/src/github.com/gogits/binding"
                ]
        },
diff --git a/gogs.go b/gogs.go
index 7bbcd803e581322b9d3274db1dc9b2d97678c1c6..552a4db27296c687b19ad155563d6fc94b48f3d1 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -11,7 +11,7 @@ import (
        "runtime"
 
        "github.com/codegangsta/cli"
-       "github.com/gogits/gogs/utils"
+       "github.com/gogits/gogs/modules/base"
 )
 
 // +build go1.1
@@ -31,12 +31,12 @@ func checkRunUser() bool {
                // TODO: log
                return false
        }
-       return user.Username == utils.Cfg.MustValue("", "RUN_USER")
+       return user.Username == base.Cfg.MustValue("", "RUN_USER")
 }
 
 func main() {
        /*if !checkRunUser() {
-               println("The command should be run as", utils.Cfg.MustValue("", "RUN_USER"))
+               println("The command should be run as", base.Cfg.MustValue("", "RUN_USER"))
                return
        }*/
 
index 0dee65478f7abe51073c38c592cf56c12815a1b5..e0ab3ca15a95d2f81ab2ed2c6ef89c3baef365e4 100644 (file)
@@ -12,7 +12,7 @@ import (
        _ "github.com/go-sql-driver/mysql"
        "github.com/lunny/xorm"
 
-       "github.com/gogits/gogs/utils"
+       "github.com/gogits/gogs/modules/base"
 )
 
 var (
@@ -41,11 +41,11 @@ type Comment struct {
 }
 
 func setEngine() {
-       dbType := utils.Cfg.MustValue("database", "DB_TYPE")
-       dbHost := utils.Cfg.MustValue("database", "HOST")
-       dbName := utils.Cfg.MustValue("database", "NAME")
-       dbUser := utils.Cfg.MustValue("database", "USER")
-       dbPwd := utils.Cfg.MustValue("database", "PASSWD")
+       dbType := base.Cfg.MustValue("database", "DB_TYPE")
+       dbHost := base.Cfg.MustValue("database", "HOST")
+       dbName := base.Cfg.MustValue("database", "NAME")
+       dbUser := base.Cfg.MustValue("database", "USER")
+       dbPwd := base.Cfg.MustValue("database", "PASSWD")
 
        uname, err := user.Current()
        if err != nil {
@@ -54,7 +54,7 @@ func setEngine() {
        }
 
        if uname.Username == "jiahuachen" {
-               dbPwd = utils.Cfg.MustValue("database", "PASSWD_jiahua")
+               dbPwd = base.Cfg.MustValue("database", "PASSWD_jiahua")
        }
 
        switch dbType {
@@ -82,9 +82,9 @@ func setEngine() {
 
        //log.Trace("Initialized database -> %s", dbName)
 
-       RepoRootPath = utils.Cfg.MustValue("repository", "ROOT")
+       RepoRootPath = base.Cfg.MustValue("repository", "ROOT")
        if uname.Username == "jiahuachen" {
-               RepoRootPath = utils.Cfg.MustValue("repository", "ROOT_jiahuachen")
+               RepoRootPath = base.Cfg.MustValue("repository", "ROOT_jiahuachen")
        }
 }
 
index 04e8c75c1b669b2a5250f93b53fa5d7ac0240f40..22b98e79750ec9722d5b4debb6fdbf5c6ef85c5e 100644 (file)
@@ -10,8 +10,9 @@ import (
        "strings"
        "time"
 
-       "github.com/gogits/gogs/utils/log"
        git "github.com/libgit2/git2go"
+
+       "github.com/gogits/gogs/modules/log"
 )
 
 type Repo struct {
index 36cdfc8a433fefcb4c54fb0612e3587ed1e0fa10..d904304f51fd9c9e3f919e4026ee956aa363633f 100644 (file)
@@ -14,13 +14,13 @@ import (
 
        "github.com/dchest/scrypt"
 
-       "github.com/gogits/gogs/utils"
+       "github.com/gogits/gogs/modules/base"
 )
 
 var UserPasswdSalt string
 
 func init() {
-       UserPasswdSalt = utils.Cfg.MustValue("security", "USER_PASSWD_SALT")
+       UserPasswdSalt = base.Cfg.MustValue("security", "USER_PASSWD_SALT")
 }
 
 // User types.
@@ -115,7 +115,7 @@ func RegisterUser(user *User) (err error) {
        }
 
        user.LowerName = strings.ToLower(user.Name)
-       user.Avatar = utils.EncodeMd5(user.Email)
+       user.Avatar = base.EncodeMd5(user.Email)
        if err = user.EncodePasswd(); err != nil {
                return err
        }
index 98c558399f0e38c95510293a18df4597faca2062..a90f3d85425418622f87f61c6dece606e2248a80 100644 (file)
@@ -14,7 +14,7 @@ import (
        "github.com/gogits/binding"
 
        "github.com/gogits/gogs/modules/base"
-       "github.com/gogits/gogs/utils/log"
+       "github.com/gogits/gogs/modules/log"
 )
 
 type Form interface {
index e25593b7379922dd90d15763150aebca3d5f30ea..215cffedb0d7de0f802b77663e12b8c7259b387c 100644 (file)
@@ -11,7 +11,7 @@ import (
 
        "github.com/gogits/gogs/models"
        "github.com/gogits/gogs/modules/base"
-       "github.com/gogits/gogs/utils/log"
+       "github.com/gogits/gogs/modules/log"
 )
 
 func SignedInId(session sessions.Session) int64 {
diff --git a/modules/base/conf.go b/modules/base/conf.go
new file mode 100644 (file)
index 0000000..19e9d68
--- /dev/null
@@ -0,0 +1,46 @@
+// 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"
+
+       "github.com/Unknwon/goconfig"
+)
+
+var Cfg *goconfig.ConfigFile
+
+func exeDir() (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(p), nil
+}
+
+func init() {
+       var err error
+       workDir, err := exeDir()
+       if err != nil {
+               fmt.Printf("Fail to get work directory: %s\n", err)
+               os.Exit(2)
+       }
+
+       cfgPath := filepath.Join(workDir, "conf", "app.ini")
+       Cfg, err = goconfig.LoadConfigFile(cfgPath)
+       if err != nil {
+               fmt.Printf("Cannot load config file '%s'\n", cfgPath)
+               os.Exit(2)
+       }
+       Cfg.BlockMode = false
+}
diff --git a/modules/base/tool.go b/modules/base/tool.go
new file mode 100644 (file)
index 0000000..eef473f
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 (
+       "crypto/md5"
+       "encoding/hex"
+)
+
+// Encode string to md5 hex value
+func EncodeMd5(str string) string {
+       m := md5.New()
+       m.Write([]byte(str))
+       return hex.EncodeToString(m.Sum(nil))
+}
diff --git a/modules/log/log.go b/modules/log/log.go
new file mode 100644 (file)
index 0000000..0634bde
--- /dev/null
@@ -0,0 +1,37 @@
+// 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 log is a wrapper of logs for short calling name.
+package log
+
+import (
+       "github.com/gogits/logs"
+)
+
+var logger *logs.BeeLogger
+
+func init() {
+       logger = logs.NewLogger(10000)
+       logger.SetLogger("console", "")
+}
+
+func Trace(format string, v ...interface{}) {
+       logger.Trace(format, v...)
+}
+
+func Info(format string, v ...interface{}) {
+       logger.Info(format, v...)
+}
+
+func Error(format string, v ...interface{}) {
+       logger.Error(format, v...)
+}
+
+func Warn(format string, v ...interface{}) {
+       logger.Warn(format, v...)
+}
+
+func Critical(format string, v ...interface{}) {
+       logger.Critical(format, v...)
+}
index 6ff949b90f29dc5dfbb962a5a546d01a361bda8a..e9ad7d1ab4e87068a3c147e7f9dc7b12fc2bec62 100644 (file)
@@ -15,7 +15,7 @@ import (
        "github.com/gogits/gogs/models"
        "github.com/gogits/gogs/modules/auth"
        "github.com/gogits/gogs/modules/base"
-       "github.com/gogits/gogs/utils/log"
+       "github.com/gogits/gogs/modules/log"
 )
 
 func Create(req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
index 658975352914c8f555b2f393d847b0a329621202..34c378061badfee5391d3cc3caba469914ec9a4f 100644 (file)
@@ -13,7 +13,7 @@ import (
        "github.com/gogits/gogs/models"
        "github.com/gogits/gogs/modules/auth"
        "github.com/gogits/gogs/modules/base"
-       "github.com/gogits/gogs/utils/log"
+       "github.com/gogits/gogs/modules/log"
 )
 
 func AddPublicKey(req *http.Request, data base.TmplData, r render.Render, session sessions.Session) {
index 7eac9b7429895d3e3530dea1ee831c6da7d6d36d..a07d79e454c77b44f818c43c3c19a38a98ad1517 100644 (file)
@@ -14,7 +14,7 @@ import (
        "github.com/gogits/gogs/models"
        "github.com/gogits/gogs/modules/auth"
        "github.com/gogits/gogs/modules/base"
-       "github.com/gogits/gogs/utils/log"
+       "github.com/gogits/gogs/modules/log"
 )
 
 func Dashboard(r render.Render, data base.TmplData, session sessions.Session) {
diff --git a/utils/conf.go b/utils/conf.go
deleted file mode 100644 (file)
index 75bd246..0000000
+++ /dev/null
@@ -1,46 +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 utils
-
-import (
-       "fmt"
-       "os"
-       "os/exec"
-       "path"
-       "path/filepath"
-
-       "github.com/Unknwon/goconfig"
-)
-
-var Cfg *goconfig.ConfigFile
-
-func exeDir() (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(p), nil
-}
-
-func init() {
-       var err error
-       workDir, err := exeDir()
-       if err != nil {
-               fmt.Printf("Fail to get work directory: %s\n", err)
-               os.Exit(2)
-       }
-
-       cfgPath := filepath.Join(workDir, "conf", "app.ini")
-       Cfg, err = goconfig.LoadConfigFile(cfgPath)
-       if err != nil {
-               fmt.Printf("Cannot load config file '%s'\n", cfgPath)
-               os.Exit(2)
-       }
-       Cfg.BlockMode = false
-}
diff --git a/utils/log/log.go b/utils/log/log.go
deleted file mode 100644 (file)
index 0634bde..0000000
+++ /dev/null
@@ -1,37 +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 log is a wrapper of logs for short calling name.
-package log
-
-import (
-       "github.com/gogits/logs"
-)
-
-var logger *logs.BeeLogger
-
-func init() {
-       logger = logs.NewLogger(10000)
-       logger.SetLogger("console", "")
-}
-
-func Trace(format string, v ...interface{}) {
-       logger.Trace(format, v...)
-}
-
-func Info(format string, v ...interface{}) {
-       logger.Info(format, v...)
-}
-
-func Error(format string, v ...interface{}) {
-       logger.Error(format, v...)
-}
-
-func Warn(format string, v ...interface{}) {
-       logger.Warn(format, v...)
-}
-
-func Critical(format string, v ...interface{}) {
-       logger.Critical(format, v...)
-}
diff --git a/utils/tool.go b/utils/tool.go
deleted file mode 100644 (file)
index 1d2db4b..0000000
+++ /dev/null
@@ -1,17 +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 utils
-
-import (
-       "crypto/md5"
-       "encoding/hex"
-)
-
-// Encode string to md5 hex value
-func EncodeMd5(str string) string {
-       m := md5.New()
-       m.Write([]byte(str))
-       return hex.EncodeToString(m.Sum(nil))
-}
diff --git a/web.go b/web.go
index fa889ba1aa91ae189abb3459e5ac17bcf6d26cb7..2b6041b12301159cf8bde532d31f69544a93eea7 100644 (file)
--- a/web.go
+++ b/web.go
@@ -18,11 +18,10 @@ import (
 
        "github.com/gogits/gogs/modules/auth"
        "github.com/gogits/gogs/modules/base"
+       "github.com/gogits/gogs/modules/log"
        "github.com/gogits/gogs/routers"
        "github.com/gogits/gogs/routers/repo"
        "github.com/gogits/gogs/routers/user"
-       "github.com/gogits/gogs/utils"
-       "github.com/gogits/gogs/utils/log"
 )
 
 var CmdWeb = cli.Command{
@@ -39,7 +38,7 @@ gogs web`,
 
 var AppHelpers template.FuncMap = map[string]interface{}{
        "AppName": func() string {
-               return utils.Cfg.MustValue("", "APP_NAME")
+               return base.Cfg.MustValue("", "APP_NAME")
        },
        "AppVer": func() string {
                return APP_VER
@@ -47,7 +46,7 @@ var AppHelpers template.FuncMap = map[string]interface{}{
 }
 
 func runWeb(*cli.Context) {
-       log.Info("%s %s", utils.Cfg.MustValue("", "APP_NAME"), APP_VER)
+       log.Info("%s %s", base.Cfg.MustValue("", "APP_NAME"), APP_VER)
 
        m := martini.Classic()
 
@@ -75,8 +74,8 @@ func runWeb(*cli.Context) {
        m.Any("/repo/list", auth.SignInRequire(false), repo.List)
 
        listenAddr := fmt.Sprintf("%s:%s",
-               utils.Cfg.MustValue("server", "HTTP_ADDR"),
-               utils.Cfg.MustValue("server", "HTTP_PORT", "3000"))
+               base.Cfg.MustValue("server", "HTTP_ADDR"),
+               base.Cfg.MustValue("server", "HTTP_PORT", "3000"))
        log.Info("Listen: %s", listenAddr)
        http.ListenAndServe(listenAddr, m)
 }