Merge utils to modules

This commit is contained in:
Unknown 2014-03-07 17:22:15 -05:00
parent a2a59f8ad1
commit 5a05d6633d
14 changed files with 30 additions and 30 deletions

View 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 {

View 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 {

46
modules/base/conf.go Normal file
View file

@ -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
}

17
modules/base/tool.go Normal file
View file

@ -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))
}

37
modules/log/log.go Normal file
View file

@ -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...)
}