excel2conf

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

excel gen

运行

./darwin_gen_excel -s="../data" -t="../gen" -skipRow=5 -skipCol=1

excel文件规则
  • 忽略不是xlsx扩展名的、开头#号的 ,如 忽略a.exl、#a.xlsx
sheet规则
忽略规则
  • 默认名Sheet
  • 中文
  • #开头
  • _c前端使用
  • _s或者不带_c、_s为后端使用,_c前端使用
跳过规则
  • 跳过行数 skipRow
  • 跳过列数 skipCol
字段规则
忽略规则
  • 没有配置字段属性

  • 没有字段名

  • 第1行策划描述

  • 第2行字段名 如 id

  • 第3行字段类型(后端) 如 int ,不配置就忽略此字段

  • 第4行字段类型(前端) 如 int

  • 第5行备注描述

  • map类型 map<int,int>//1:2,3:4

    • 类型:map<int,long>,map<int,string>等
  • 一维数组 1,2,3,4或者[1,2,3,4]

    • 类型:int[],long[],string[],float[],double[]等
  • 二维数组 [[1,2],[3,4]],单数据可以[[1,2]]或[1,2]

    • 类型:int[][],long[][],string[][],float[][],double[][]等
  • 基本类型 int(备注等于int32) int32 long float double string

类型
  • 主键必须是 int int32 int64 string
  • 字段支持的类型

stringTyp = "string"

intTyp = "int"
int32Typ = "int32"
int64Typ = "int64"

float32Typ = "float"
float64Typ = "double"

repeatedStringTyp = "string[]"
repeatedIntTyp = "int[]"
repeatedInt32Typ = "int32[]"
repeatedInt64Typ = "int64[]"
repeatedFloat32Typ = "float[]"
repeatedFloat64Typ = "double[]"

repeatedInt2Typ = "int[][]"
repeatedString2Typ = "string[][]"
repeatedFloat2Typ = "float[][]"
repeatedDouble2Typ = "double[][]"

mapInt32String = "map<int32,string>"
mapInt32In32 = "map<int32,int32>"
mapInt64String = "map<int64,string>"
mapInt64Int32 = "map<int64,int32>"
mapInt64Int64   = "map<int64,int64>"
mapStringString = "map<string,string>"
mapStringInt32 = "map<string,int32>"
mapIntInt = "map<int,int>"
mapIntString = "map<int,string>"
mapInt32Float32 = "map<int32,float>"
mapIntFloat32 = "map<int,float>"
mapInt32Float64 = "map<int32,double>"
表数据检测

服务器字段后加入@ 例如 int@自定义注解名称

?增加额外参数

例如 map<int,int>@Resource?1,2

golang 使用
  • 生成配置文件 bin中可执行文件 -s excel源地址 -t gen目标地址
  • 加载
    zap_log.Init(false, zap.DebugLevel)
    config.InitWithLoader(conf_loader.AddLoader)
    conf_loader.MustInitLocal("/Users/nullzZ/works/null-kit/excel2conf/gen/rawdata", true, zap_log.Logger)
    
  • 获取数据 c, ok := config.GetTest("1")
  • 另一种获取数据的方式 c,ok:=config.Get("SheetName",id),
    • id需要注意对应的类型
    • 如果索引是int32 c,ok:=config.Get("SheetName",id)
    • 最好不要使用此方法 此方法可用于表检查
  • 自定义注解检测字段内数据
  m := make(map[string]func(i interface{}, param string) bool)
  m["ItemData"] = func(i interface{}, param string) bool {
      d, ok := i.(map[int32]int32)
      if !ok {
          return false
      }
      for k, _ := range d {
          _, h := config.GetItemData(k)
          if !h {
              return false
          }
      }
      return true
  }
  m["InConf"] = func(i interface{}, param string) bool {
      d, ok := i.(map[int32]int32)
      if !ok {
          return false
      }
      for k, _ := range d {
          _, h := config.Get(param, k)
          if !h {
              return false
          }
      }
      return true
  }
  
  config.InitWithLoader(conf_loader.AddLoader)
  config.InitCheckerFunc(m)//注册自定义注解函数
  conf_loader.AddChecker(config.Checker)//加载检测方法
  conf_loader.MustInitLocal("/Users/nullzZ/works/null-kit/excel2conf/gen/rawdata", true, zap_log.Logger)
build
mac和linux
  • CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o linux_gen_excel main.go
  • CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags '-w -s' -o darwin_gen_excel main.go
  • CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags '-w -s' -o win_gen_excel.exe main.go
windows编译
  • go build -ldflags '-w -s' main.go .\win_gen.exe -s=C:\null-kit\excel2conf\data -t=C:\null-kit\excel2conf\gen
遇到问题,记录一下
待开发

Documentation

Index

Constants

View Source
const (
	FieldName      = 1
	ClientFieldTyp = 2
	ServerFieldTyp = 3
	FieldAnn       = 4 //注释
	Packaged       = "config"
	GenJsonName    = "_conf.gen.json"
)

Variables

View Source
var (
	ErrorSourcePath = errors.New("ReadExcel sourcePath nil")
	ErrorToPath     = errors.New("ReadExcel stoPath nil")
	ErrorMaxRow     = errors.New("ReadExcel row<4")
)

Functions

func CheckPriRepeat

func CheckPriRepeat(data []*model.GenJsonData2) error

CheckPriRepeat 检测主键是否重复

func Gen added in v1.0.1

func Gen(gen *GenerateExcel)

Types

type GenCfg

type GenCfg struct {
	SkipRowNumber int //每个sheet开始行数
	SkipColNumber int //跳过列数
}

type GenJson

type GenJson struct{}

func (*GenJson) Gen

func (g *GenJson) Gen(structModel *model.ConfigData) error

type GenOption

type GenOption func(cfg *GenCfg)

func WithSkipCol

func WithSkipCol(skipCol int) GenOption

func WithSkipRow

func WithSkipRow(skipRow int) GenOption

type GenerateExcel

type GenerateExcel struct {
	// contains filtered or unexported fields
}

*

  • 将excel中的前四列转化为struct
  • 第一列字段名 如 id
  • 第二列字段类型 如 int
  • 第三列备注
  • 第四列s,c,all s表示服务端使用 c表示客户端使用 all表示都使用

func NewGenerateExcel

func NewGenerateExcel(sourcePath, toPath string, opt ...GenOption) *GenerateExcel

func (*GenerateExcel) AddGen

func (g *GenerateExcel) AddGen(gen IGen)

AddGen 增加单sheet生成器

func (*GenerateExcel) AddGlobalGen

func (g *GenerateExcel) AddGlobalGen(gen IGlobalGen)

AddGlobalGen 增加全局生成器

func (*GenerateExcel) GenSheet

func (g *GenerateExcel) GenSheet(sheet *xlsx.Sheet, sheetName, pack string) error

func (*GenerateExcel) ReadFile

func (g *GenerateExcel) ReadFile() error

type IGen

type IGen interface {
	Gen(structModel *model.ConfigData) error
}

type IGlobalGen

type IGlobalGen interface {
	Gen(packaged, toPath string, configDatas *[]*model.ConfigData) error
}

Directories

Path Synopsis
pkg
str
zaplog
@Author: nullzz @Date: 2022/3/23 7:37 下午 @Version: 1.0 @DEC:
@Author: nullzz @Date: 2022/3/23 7:37 下午 @Version: 1.0 @DEC:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址