Browse Source

add Reverse: for v1.0.7

tags/v1.0.7
Hjj 2 years ago
parent
commit
c540da69d8
2 changed files with 18 additions and 23 deletions
  1. +1
    -4
      coupon_test.go
  2. +17
    -19
      db/db.go

+ 1
- 4
coupon_test.go View File

@@ -7,10 +7,7 @@ import (
)

func TestCouponCommCheck(t *testing.T) {
err := Init("119.23.182.117:3306", "fnuoos_test1", "root", "Fnuo123com@")
if err != nil {
t.Errorf("Reverse == %s", err)
}

req := md.CouponCheckRequest{
CouponAmount: "",
Uid: "21702",


+ 17
- 19
db/db.go View File

@@ -5,10 +5,8 @@ import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql" //必须导入mysql驱动,否则会panic
"os"
"time"
"xorm.io/xorm"
"xorm.io/xorm/log"
)

var Db *xorm.Engine
@@ -17,7 +15,7 @@ var Db *xorm.Engine
func InitDB(c *md.DBCfg) error {
var (
err error
f *os.File
//f *os.File
)
//创建Orm引擎
if Db, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", c.User, c.Psw, c.Host, c.Name)); err != nil {
@@ -29,22 +27,22 @@ func InitDB(c *md.DBCfg) error {
if err = Db.Ping(); err != nil { //尝试ping数据库
return err
}
if c.ShowLog { //根据配置文件设置日志
Db.ShowSQL(true) //设置是否打印sql
Db.Logger().SetLevel(0) //设置日志等级
//修改日志文件存放路径文件名是%s.log
path := fmt.Sprintf(c.Path, c.Name)
f, err = os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777)
if err != nil {
os.RemoveAll(c.Path)
if f, err = os.OpenFile(c.Path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777); err != nil {
return err
}
}
logger := log.NewSimpleLogger(f)
logger.ShowSQL(true)
Db.SetLogger(logger)
}
//if c.ShowLog { //根据配置文件设置日志
// Db.ShowSQL(true) //设置是否打印sql
// Db.Logger().SetLevel(0) //设置日志等级
// //修改日志文件存放路径文件名是%s.log
// path := fmt.Sprintf(c.Path, c.Name)
// f, err = os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777)
// if err != nil {
// os.RemoveAll(c.Path)
// if f, err = os.OpenFile(c.Path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777); err != nil {
// return err
// }
// }
// logger := log.NewSimpleLogger(f)
// logger.ShowSQL(true)
// Db.SetLogger(logger)
//}
return nil
}



Loading…
Cancel
Save