log.go 1.3 KB
Newer Older
Y
Your Name 已提交
1
package configlog
E
eoLinker API Management 已提交
2 3

import (
黄孟柱 已提交
4 5
	"github.com/eolinker/goku-api-gateway/common/database"
	entity "github.com/eolinker/goku-api-gateway/server/entity/config-log"
E
eoLinker API Management 已提交
6 7
)

Y
Your Name 已提交
8 9 10
const sqlSelect = "SELECT `name`,`enable`,`dir`,`file`,`level`,`period`,`expire`,`fields` FROM `goku_config_log` WHERE `name` = ? LIMIT 1;"
const sqlInsert = "INSERT  INTO `goku_config_log`(`name`,`enable`,`dir`,`file`,`level`,`period`,`expire`,`fields`)VALUES(?,?,?,?,?,?,?,?)ON DUPLICATE KEY UPDATE `enable`=VALUES(`enable`),`dir`=VALUES(`dir`),`file`=VALUES(`file`),`level`=VALUES(`level`),`period`=VALUES(`period`),`expire`=VALUES(`expire`),`fields`=VALUES(`fields`);"

Y
Your Name 已提交
11
//Get 通过名称获取日志配置
Y
Your Name 已提交
12
func Get(name string) (*entity.LogConfig, error) {
E
eoLinker API Management 已提交
13
	stmt, e := database.GetConnection().Prepare(sqlSelect)
Y
Your Name 已提交
14 15
	if e != nil {
		return nil, e
E
eoLinker API Management 已提交
16
	}
Y
Your Name 已提交
17 18
	ent := &entity.LogConfig{}
	err := stmt.QueryRow(name).Scan(
E
eoLinker API Management 已提交
19 20 21 22 23 24 25 26
		&ent.Name,
		&ent.Enable,
		&ent.Dir,
		&ent.File,
		&ent.Level,
		&ent.Period,
		&ent.Expire,
		&ent.Fields,
Y
Your Name 已提交
27 28 29
	)
	if err != nil {
		return nil, err
E
eoLinker API Management 已提交
30
	}
Y
Your Name 已提交
31
	return ent, nil
E
eoLinker API Management 已提交
32 33
}

Y
Your Name 已提交
34
//Set 设置日志配置
Y
Your Name 已提交
35
func Set(ent *entity.LogConfig) error {
E
eoLinker API Management 已提交
36
	stmt, e := database.GetConnection().Prepare(sqlInsert)
Y
Your Name 已提交
37
	if e != nil {
E
eoLinker API Management 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
		return e
	}
	_, err := stmt.Exec(
		ent.Name,
		ent.Enable,
		ent.Dir,
		ent.File,
		ent.Level,
		ent.Period,
		ent.Expire,
		ent.Fields,
	)

	return err
}