26 lines
593 B
Go
26 lines
593 B
Go
package export
|
||
|
||
import (
|
||
"math/rand"
|
||
)
|
||
|
||
type MysqlDataFetcher struct {
|
||
Config string
|
||
}
|
||
|
||
func (mf *MysqlDataFetcher) Fetch(sql string) (*Data, error) {
|
||
rows := make([]interface{}, 0, 6)
|
||
// 插入6个随机数组成的切片,模拟查询要返回的数据集
|
||
rows = append(rows, rand.Perm(5), rand.Perm(5), rand.Perm(5), rand.Perm(5), rand.Perm(5), rand.Perm(5))
|
||
return &Data{
|
||
Title: []string{"字段1", "字段2", "字段3", "字段4", "字段5"},
|
||
Data: rows,
|
||
}, nil
|
||
}
|
||
|
||
func NewMysqlDataFetcher(configStr string) DataFetcher {
|
||
return &MysqlDataFetcher{
|
||
Config: configStr,
|
||
}
|
||
}
|