移除配置导表(不合理)
This commit is contained in:
parent
859eb8b7e4
commit
c0e12b082d
|
@ -1,6 +0,0 @@
|
|||
package configuration
|
||||
|
||||
// Analyzer 分析器接口,通过分析特定文件产生配置文件
|
||||
type Analyzer interface {
|
||||
Analyze(filePath string) (map[string]Configuration, error)
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package analyzer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kercylan98/minotaur/exporter/configuration"
|
||||
"github.com/kercylan98/minotaur/exporter/configuration/golang"
|
||||
"github.com/kercylan98/minotaur/utils/log"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"go.uber.org/zap"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Default struct {
|
||||
}
|
||||
|
||||
func (slf *Default) Analyze(filePath string) (map[string]configuration.Configuration, error) {
|
||||
file, err := excelize.OpenFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var configs = make(map[string]configuration.Configuration)
|
||||
|
||||
for _, sheetName := range file.GetSheetList() {
|
||||
|
||||
rs, err := file.GetRows(sheetName)
|
||||
if err != nil {
|
||||
log.Error("Analyze", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
var rows = make(map[int][]string)
|
||||
for ri, row := range rs {
|
||||
r := make([]string, 0, len(row))
|
||||
for _, col := range row {
|
||||
r = append(r, col)
|
||||
}
|
||||
rows[ri] = r
|
||||
}
|
||||
|
||||
if len(rows[0]) < 2 || len(rows[1]) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
var (
|
||||
name = strings.TrimSpace(rows[0][1])
|
||||
indexCountStr = strings.TrimSpace(rows[1][1])
|
||||
indexCount int
|
||||
)
|
||||
|
||||
if name == "" || indexCountStr == "" {
|
||||
continue
|
||||
} else {
|
||||
indexCount, err = strconv.Atoi(indexCountStr)
|
||||
if err != nil {
|
||||
log.Error("Analyze", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if len(rows[3]) < 2 || len(rows[4]) < 2 || len(rows[5]) < 2 || len(rows[6]) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
config := golang.NewConfiguration(name)
|
||||
|
||||
for i := range rows[3] {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
var field = golang.NewField(i, rows[4][i], golang.GetFieldType(rows[5][i]), i-1 < indexCount)
|
||||
config.AddField(field)
|
||||
}
|
||||
|
||||
fmt.Println(config.GetStruct())
|
||||
}
|
||||
|
||||
return configs, nil
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package analyzer
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDefault_Analyze(t *testing.T) {
|
||||
var d = new(Default)
|
||||
d.Analyze("./template.xlsx")
|
||||
}
|
Binary file not shown.
|
@ -1,8 +0,0 @@
|
|||
package configuration
|
||||
|
||||
// Configuration 配置
|
||||
type Configuration interface {
|
||||
GetName() string
|
||||
GetFields() []Field
|
||||
AddField(field Field)
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package configuration
|
||||
|
||||
// Field 配置字段
|
||||
type Field interface {
|
||||
GetID() int
|
||||
GetName() string
|
||||
GetType() FieldType
|
||||
IsIndex() bool
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package configuration
|
||||
|
||||
const (
|
||||
FieldTypeString = FieldType(iota)
|
||||
FieldTypeInt
|
||||
FieldTypeInt8
|
||||
FieldTypeInt16
|
||||
FieldTypeInt32
|
||||
FieldTypeInt64
|
||||
FieldTypeUint
|
||||
FieldTypeUint8
|
||||
FieldTypeUint16
|
||||
FieldTypeUint32
|
||||
FieldTypeUint64
|
||||
FieldTypeFloat32
|
||||
FieldTypeFloat64
|
||||
FieldTypeByte
|
||||
FieldTypeBool
|
||||
FieldTypeRune
|
||||
FieldTypeSliceString
|
||||
FieldTypeSliceInt
|
||||
FieldTypeSliceInt8
|
||||
FieldTypeSliceInt16
|
||||
FieldTypeSliceInt32
|
||||
FieldTypeSliceInt64
|
||||
FieldTypeSliceUint
|
||||
FieldTypeSliceUint8
|
||||
FieldTypeSliceUint16
|
||||
FieldTypeSliceUint32
|
||||
FieldTypeSliceUint64
|
||||
FieldTypeSliceFloat32
|
||||
FieldTypeSliceFloat64
|
||||
FieldTypeSliceByte
|
||||
FieldTypeSliceBool
|
||||
FieldTypeSliceRune
|
||||
)
|
||||
|
||||
type FieldType byte
|
|
@ -1,46 +0,0 @@
|
|||
package golang
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kercylan98/minotaur/exporter/configuration"
|
||||
"github.com/kercylan98/minotaur/utils/hash"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NewConfiguration(name string) *Configuration {
|
||||
return &Configuration{
|
||||
name: name,
|
||||
fields: hash.NewSortMap[int, configuration.Field](),
|
||||
}
|
||||
}
|
||||
|
||||
type Configuration struct {
|
||||
name string
|
||||
fields *hash.SortMap[int, configuration.Field]
|
||||
}
|
||||
|
||||
func (slf *Configuration) GetName() string {
|
||||
return slf.name
|
||||
}
|
||||
|
||||
func (slf *Configuration) GetFields() []configuration.Field {
|
||||
return slf.fields.ToSliceSort()
|
||||
}
|
||||
|
||||
func (slf *Configuration) AddField(field configuration.Field) {
|
||||
slf.fields.Set(field.GetID(), field)
|
||||
}
|
||||
|
||||
func (slf *Configuration) GetStruct() string {
|
||||
var index string
|
||||
var structStr string
|
||||
for _, field := range slf.GetFields() {
|
||||
if field.IsIndex() {
|
||||
index += fmt.Sprintf("map[%s]", field.GetType())
|
||||
}
|
||||
structStr += fmt.Sprintf("%s %s\r\n", strings.ToUpper(field.GetName()[:1])+field.GetName()[1:], field.GetType().String())
|
||||
}
|
||||
index = fmt.Sprintf("%s*%s", index, strings.ToUpper(slf.GetName()[:1])+slf.GetName()[1:])
|
||||
structStr = fmt.Sprintf("type %s struct {\r\n %s \r\n}", strings.ToUpper(slf.GetName()[:1])+slf.GetName()[1:], structStr)
|
||||
return fmt.Sprintf("%s \r\n%s", index, structStr)
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package golang
|
||||
|
||||
import (
|
||||
"github.com/kercylan98/minotaur/exporter/configuration"
|
||||
)
|
||||
|
||||
func NewField(id int, name string, fieldType configuration.FieldType, isIndex bool) *Field {
|
||||
return &Field{
|
||||
id: id,
|
||||
name: name,
|
||||
fieldType: fieldType,
|
||||
isIndex: isIndex,
|
||||
}
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
id int
|
||||
name string
|
||||
fieldType configuration.FieldType
|
||||
isIndex bool
|
||||
}
|
||||
|
||||
func (slf *Field) GetID() int {
|
||||
return slf.id
|
||||
}
|
||||
|
||||
func (slf *Field) GetName() string {
|
||||
return slf.name
|
||||
}
|
||||
|
||||
func (slf *Field) GetType() configuration.FieldType {
|
||||
return slf.fieldType
|
||||
}
|
||||
|
||||
func (slf *Field) IsIndex() bool {
|
||||
return slf.isIndex
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
package golang
|
||||
|
||||
import "github.com/kercylan98/minotaur/exporter/configuration"
|
||||
|
||||
func GetFieldType(fieldType string) configuration.FieldType {
|
||||
switch fieldType {
|
||||
case "string":
|
||||
return configuration.FieldTypeString
|
||||
case "int":
|
||||
return configuration.FieldTypeInt
|
||||
case "int8":
|
||||
return configuration.FieldTypeInt8
|
||||
case "int16":
|
||||
return configuration.FieldTypeInt16
|
||||
case "int32":
|
||||
return configuration.FieldTypeInt32
|
||||
case "int64":
|
||||
return configuration.FieldTypeInt64
|
||||
case "uint":
|
||||
return configuration.FieldTypeUint
|
||||
case "uint8":
|
||||
return configuration.FieldTypeUint8
|
||||
case "uint16":
|
||||
return configuration.FieldTypeUint16
|
||||
case "uint32":
|
||||
return configuration.FieldTypeUint32
|
||||
case "uint64":
|
||||
return configuration.FieldTypeUint64
|
||||
case "float32":
|
||||
return configuration.FieldTypeFloat32
|
||||
case "float64":
|
||||
return configuration.FieldTypeFloat64
|
||||
case "byte":
|
||||
return configuration.FieldTypeByte
|
||||
case "bool":
|
||||
return configuration.FieldTypeBool
|
||||
case "rune":
|
||||
return configuration.FieldTypeRune
|
||||
case "[]string":
|
||||
return configuration.FieldTypeSliceString
|
||||
case "[]int":
|
||||
return configuration.FieldTypeSliceInt
|
||||
case "[]int8":
|
||||
return configuration.FieldTypeSliceInt8
|
||||
case "[]int16":
|
||||
return configuration.FieldTypeSliceInt16
|
||||
case "[]int32":
|
||||
return configuration.FieldTypeSliceInt32
|
||||
case "[]int64":
|
||||
return configuration.FieldTypeSliceInt64
|
||||
case "[]uint":
|
||||
return configuration.FieldTypeSliceUint
|
||||
case "[]uint8":
|
||||
return configuration.FieldTypeSliceUint8
|
||||
case "[]uint16":
|
||||
return configuration.FieldTypeSliceUint16
|
||||
case "[]uint32":
|
||||
return configuration.FieldTypeSliceUint32
|
||||
case "[]uint64":
|
||||
return configuration.FieldTypeSliceUint64
|
||||
case "[]float32":
|
||||
return configuration.FieldTypeSliceFloat32
|
||||
case "[]float64":
|
||||
return configuration.FieldTypeSliceFloat64
|
||||
case "[]byte":
|
||||
return configuration.FieldTypeSliceByte
|
||||
case "[]bool":
|
||||
return configuration.FieldTypeSliceBool
|
||||
case "[]rune":
|
||||
return configuration.FieldTypeSliceRune
|
||||
default:
|
||||
return configuration.FieldTypeString
|
||||
}
|
||||
}
|
||||
|
||||
func GetFieldTypeName(fieldType configuration.FieldType) string {
|
||||
switch fieldType {
|
||||
case configuration.FieldTypeString:
|
||||
return "string"
|
||||
case configuration.FieldTypeInt:
|
||||
return "int"
|
||||
case configuration.FieldTypeInt8:
|
||||
return "int8"
|
||||
case configuration.FieldTypeInt16:
|
||||
return "int16"
|
||||
case configuration.FieldTypeInt32:
|
||||
return "int32"
|
||||
case configuration.FieldTypeInt64:
|
||||
return "int64"
|
||||
case configuration.FieldTypeUint:
|
||||
return "uint"
|
||||
case configuration.FieldTypeUint8:
|
||||
return "uint8"
|
||||
case configuration.FieldTypeUint16:
|
||||
return "uint16"
|
||||
case configuration.FieldTypeUint32:
|
||||
return "uint32"
|
||||
case configuration.FieldTypeUint64:
|
||||
return "uint64"
|
||||
case configuration.FieldTypeFloat32:
|
||||
return "float32"
|
||||
case configuration.FieldTypeFloat64:
|
||||
return "float64"
|
||||
case configuration.FieldTypeByte:
|
||||
return "byte"
|
||||
case configuration.FieldTypeBool:
|
||||
return "bool"
|
||||
case configuration.FieldTypeRune:
|
||||
return "rune"
|
||||
case configuration.FieldTypeSliceString:
|
||||
return "[]string"
|
||||
case configuration.FieldTypeSliceInt:
|
||||
return "[]int"
|
||||
case configuration.FieldTypeSliceInt8:
|
||||
return "[]int8"
|
||||
case configuration.FieldTypeSliceInt16:
|
||||
return "[]int16"
|
||||
case configuration.FieldTypeSliceInt32:
|
||||
return "[]int32"
|
||||
case configuration.FieldTypeSliceInt64:
|
||||
return "[]int64"
|
||||
case configuration.FieldTypeSliceUint:
|
||||
return "[]uint"
|
||||
case configuration.FieldTypeSliceUint8:
|
||||
return "[]uint8"
|
||||
case configuration.FieldTypeSliceUint16:
|
||||
return "[]uint16"
|
||||
case configuration.FieldTypeSliceUint32:
|
||||
return "[]uint32"
|
||||
case configuration.FieldTypeSliceUint64:
|
||||
return "[]uint64"
|
||||
case configuration.FieldTypeSliceFloat32:
|
||||
return "[]float32"
|
||||
case configuration.FieldTypeSliceFloat64:
|
||||
return "[]float64"
|
||||
case configuration.FieldTypeSliceByte:
|
||||
return "[]byte"
|
||||
case configuration.FieldTypeSliceBool:
|
||||
return "[]bool"
|
||||
case configuration.FieldTypeSliceRune:
|
||||
return "[]rune"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue