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

import (
Y
Your Name 已提交
4 5 6
	"database/sql"

	"github.com/eolinker/goku-api-gateway/server/dao"
黄孟柱 已提交
7
	entity "github.com/eolinker/goku-api-gateway/server/entity/config-log"
E
eoLinker API Management 已提交
8 9
)

Y
Your Name 已提交
10
const sqlSelect = "SELECT `name`,`enable`,`dir`,`file`,`level`,`period`,`expire`,`fields` FROM `goku_config_log` WHERE `name` = ? LIMIT 1;"
Y
Your Name 已提交
11
const sqlInsert = "REPLACE INTO `goku_config_log`(`name`,`enable`,`dir`,`file`,`level`,`period`,`expire`,`fields`)VALUES(?,?,?,?,?,?,?,?);"
Y
Your Name 已提交
12

Y
Your Name 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
//ConfigLogDao ConfigLogDao
type ConfigLogDao struct {
	db *sql.DB
}

//NewConfigLogDao new ConfigLogDao
func NewConfigLogDao() *ConfigLogDao {
	return &ConfigLogDao{}
}

//Create create
func (d *ConfigLogDao) Create(db *sql.DB) (interface{}, error) {
	d.db = db
	var i dao.ConfigLogDao = d
	return &i, nil
}

Y
Your Name 已提交
30
//Get get
Y
Your Name 已提交
31 32
func (d *ConfigLogDao) Get(name string) (*entity.LogConfig, error) {
	stmt, e := d.db.Prepare(sqlSelect)
Y
Your Name 已提交
33 34
	if e != nil {
		return nil, e
E
eoLinker API Management 已提交
35
	}
36
	defer stmt.Close()
Y
Your Name 已提交
37 38
	ent := &entity.LogConfig{}
	err := stmt.QueryRow(name).Scan(
E
eoLinker API Management 已提交
39 40 41 42 43 44 45 46
		&ent.Name,
		&ent.Enable,
		&ent.Dir,
		&ent.File,
		&ent.Level,
		&ent.Period,
		&ent.Expire,
		&ent.Fields,
Y
Your Name 已提交
47 48 49
	)
	if err != nil {
		return nil, err
E
eoLinker API Management 已提交
50
	}
Y
Your Name 已提交
51
	return ent, nil
E
eoLinker API Management 已提交
52 53
}

Y
Your Name 已提交
54
//Set set
Y
Your Name 已提交
55 56
func (d *ConfigLogDao) Set(ent *entity.LogConfig) error {
	stmt, e := d.db.Prepare(sqlInsert)
Y
Your Name 已提交
57
	if e != nil {
E
eoLinker API Management 已提交
58 59
		return e
	}
60
	defer stmt.Close()
E
eoLinker API Management 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73
	_, err := stmt.Exec(
		ent.Name,
		ent.Enable,
		ent.Dir,
		ent.File,
		ent.Level,
		ent.Period,
		ent.Expire,
		ent.Fields,
	)

	return err
}