excel-export/biz/export/mysql_data_fetcher.go

36 lines
707 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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