log.go 1.1 KB
Newer Older
Y
Your Name 已提交
1
package config_log
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
const sqlSelect = "SELECT `name`,`enable`,`dir`,`file`,`level`,`period`,`expire`,`fields` FROM `goku_config_log` WHERE `name` = ? LIMIT 1;"
Y
Your Name 已提交
9
const sqlInsert = "REPLACE INTO `goku_config_log`(`name`,`enable`,`dir`,`file`,`level`,`period`,`expire`,`fields`)VALUES(?,?,?,?,?,?,?,?);"
Y
Your Name 已提交
10

Y
Your Name 已提交
11
//Get 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
	}
17
	defer stmt.Close()
Y
Your Name 已提交
18 19
	ent := &entity.LogConfig{}
	err := stmt.QueryRow(name).Scan(
E
eoLinker API Management 已提交
20 21 22 23 24 25 26 27
		&ent.Name,
		&ent.Enable,
		&ent.Dir,
		&ent.File,
		&ent.Level,
		&ent.Period,
		&ent.Expire,
		&ent.Fields,
Y
Your Name 已提交
28 29 30
	)
	if err != nil {
		return nil, err
E
eoLinker API Management 已提交
31
	}
Y
Your Name 已提交
32
	return ent, nil
E
eoLinker API Management 已提交
33 34
}

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

	return err
}