comm.go
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package tests
import (
"fmt"
"github.com/astaxie/beego"
_ "github.com/go-sql-driver/mysql"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis"
"os"
"path/filepath"
"runtime"
"sync"
)
var one sync.Once
func Init() {
one.Do(func() {
_, file, _, _ := runtime.Caller(0)
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
beego.TestBeegoInit(apppath)
path, _ := os.Getwd()
filename := "app.conf"
beego.LoadAppConfig("ini", filepath.Join(path, "conf", filename))
log.InitLog(config.Logger{
Filename: "app.log",
Level: "7", //7 单元test时 可以把级别设置低一点 减少日志
})
redisSource := fmt.Sprintf("%v:%v", beego.AppConfig.String("redis_add"), beego.AppConfig.String("redis_add_port"))
err := redis.InitWithDb(100, redisSource, beego.AppConfig.String("redis_auth"), "0")
if err != nil {
log.Fatal(err)
panic(err)
}
dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?loc=Asia%%2FShanghai",
beego.AppConfig.String("mysql_user"),
beego.AppConfig.String("mysql_password"),
beego.AppConfig.String("mysql_host"),
beego.AppConfig.String("mysql_port"),
beego.AppConfig.String("mysql_db_name"),
)
orm.NewBeeormEngine(config.Mysql{
DataSource: dataSource,
MaxIdle: 100,
MaxOpen: 100,
})
//protocol.InitMessageCode()
})
}