lib

package
v0.0.0-...-313d28e Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RowAttr = iota
	RowType
	RowID
	RowComment
	RowData
)

Row index in sheet

View Source
const (
	Req     = "required"
	Opt     = "optional"
	Rep     = "repeated"
	OptStru = "optional_struct"
	Unique  = "unique"
)

Field type for proto2

Variables

View Source
var (
	ErrRequiredFieldEmpty = errors.New("required field is empty")
	ErrFormatInvalid      = errors.New("invalid cell value")
)
View Source
var (
	// INDENT Use 2 spaces
	INDENT = "  "
)

Functions

func CacheInit

func CacheInit()

CacheInit initialize cacher and read from file

func ClearCache

func ClearCache()

ClearCache remove saved records and initialize a new cacher

func CopyChangedDataFiles

func CopyChangedDataFiles(fName string) error

CopyChangedDataFiles if a data file is changed, copy data file to output dir

func CopyChangedProtoFiles

func CopyChangedProtoFiles(fName string) error

CopyChangedProtoFiles if a proto file is changed, copy both proto and data file to output dir

func IsDataChanged

func IsDataChanged(ps *ProtoSheet) bool

func IsProtoChanged

func IsProtoChanged(ps *ProtoSheet) bool

IsProtoChanged check and update previous proto info

func IsSheetExists

func IsSheetExists(xlsxName string) bool

IsSheetExists check if file exist in xlsx folder

func IsTitleValid

func IsTitleValid(title string) bool

IsTitleValid check if the first letter of a xlsx title is uppercase.

func IsXlsxChanged

func IsXlsxChanged(filename string) bool

IsXlsxChanged check if file has the same hash value as before

func ReadSheet

func ReadSheet(fileName, sheetName string) error

ReadSheet Read data pair from *.config

func ResetConfigCache

func ResetConfigCache()

ResetConfigCache clear current config data

func Run

func Run(isCacheOn, isUseGoroutine bool)

Run execute the xlsx2pb and output proto files and binary data files

Types

type CConfig

type CConfig struct {
	Config Config `toml:"Config"`
}

type CacheStatus

type CacheStatus int
const (
	None CacheStatus = iota
	Remained
	Updated
	New
)

type Cacher

type Cacher struct {
	XlsxInfos  map[string]*DataInfo `json:"xlsx_info"`
	ProtoInfos map[string]*DataInfo `json:"proto_info"`
	DataInfos  map[string]*DataInfo `json:"data_info"`
	// contains filtered or unexported fields
}

Cacher is handler for cache

func (*Cacher) Load

func (c *Cacher) Load() error

Load read data from json cache file

func (*Cacher) Save

func (c *Cacher) Save() error

Save write current data to cache file as json

type CommonInfo

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

CommonInfo is common info for val, opt struct and repeat

type Config

type Config struct {
	ConfigRegExp     string `toml:"config_reg_exp"`
	XlsxPath         string `toml:"xlsx_path"`
	XlsxExt          string `toml:"xlsx_ext"`
	PackageName      string `toml:"package_name"`
	UseProto3        bool   `toml:"use_proto3"`
	ProtoOutPath     string `toml:"proto_path"`
	ProtoOutExt      string `toml:"proto_ext"`
	DataOutPath      string `toml:"data_path"`
	DataOutExt       string `toml:"data_ext"`
	CacheFile        string `toml:"cache_file"`
	ChangeOutputPath string `toml:"change_output_path"`
	ChangeLog        string `toml:"change_log"`
}

func (*Config) CheckDirs

func (c *Config) CheckDirs()

func (*Config) LoadConfig

func (c *Config) LoadConfig()

func (*Config) ReplaceRelPaths

func (c *Config) ReplaceRelPaths()

type DataInfo

type DataInfo struct {
	Name  string      `json:"name"`
	MD5   []byte      `json:"md5"`
	State CacheStatus `json:"-"` // 0: previous 1: updated 2: new
}

XlsxInfo contains sheet information in xlsx files

type OptStruct

type OptStruct struct {
	CommonInfo
	// contains filtered or unexported fields
}

OptStruct is a struct contains one or more variants

type ProtoIn

type ProtoIn struct {
	Name string
	// contains filtered or unexported fields
}

ProtoIn contains data read from xlsx

type ProtoOut

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

ProtoOut controls how to output proto file

type ProtoSheet

type ProtoSheet struct {
	ProtoIn
	ProtoOut
	// contains filtered or unexported fields
}

ProtoSheet is used to generate proto file buf used to store data binary

func (*ProtoSheet) AddMessageArray

func (pr *ProtoSheet) AddMessageArray()

AddMessageArray add an array for current message as XXX_ARRAY

func (*ProtoSheet) AddMessageHead

func (pr *ProtoSheet) AddMessageHead(name string)

AddMessageHead add a proto message head

func (*ProtoSheet) AddMessageTail

func (pr *ProtoSheet) AddMessageTail()

AddMessageTail add a proto message tail

func (*ProtoSheet) AddOneDefine

func (pr *ProtoSheet) AddOneDefine(isRepeat bool, comment, p2type, typ, name, defaultValStr string, idx int)

AddOneDefine add a proto defination

func (*ProtoSheet) AddOneEmptyLine

func (pr *ProtoSheet) AddOneEmptyLine()

AddOneEmptyLine add an empty line

func (*ProtoSheet) AddOptStructTail

func (pr *ProtoSheet) AddOptStructTail(opts *OptStruct)

func (*ProtoSheet) AddOptionalStruct

func (pr *ProtoSheet) AddOptionalStruct(optS *OptStruct)

func (*ProtoSheet) AddPreHead

func (pr *ProtoSheet) AddPreHead()

AddPreHead add syntax and package info

func (*ProtoSheet) AddRepeat

func (pr *ProtoSheet) AddRepeat(repeat *Repeat)

AddRepeat add repeat struct

func (*ProtoSheet) AddRepeatTail

func (pr *ProtoSheet) AddRepeatTail(repeat *Repeat)

AddRepeatTail add repeat declare

func (*ProtoSheet) AddVal

func (pr *ProtoSheet) AddVal(sh *Val)

AddVal add a proto variable define

func (*ProtoSheet) DataHash

func (pr *ProtoSheet) DataHash()

Hash generate hash of proto content

func (*ProtoSheet) DecreaseIndent

func (pr *ProtoSheet) DecreaseIndent()

DecreaseIndent decrease indent

func (*ProtoSheet) GenProto

func (pr *ProtoSheet) GenProto()

GenProto genenate proto file content

func (*ProtoSheet) IncreaseIndent

func (pr *ProtoSheet) IncreaseIndent()

IncreaseIndent increase indent

func (*ProtoSheet) ProtoHash

func (pr *ProtoSheet) ProtoHash()

Hash generate hash of proto content

func (*ProtoSheet) WriteData

func (pr *ProtoSheet) WriteData()

func (*ProtoSheet) WriteProto

func (pr *ProtoSheet) WriteProto()

WriteProto output proto file to "./proto/sheetname.proto"

type Repeat

type Repeat struct {
	CommonInfo
	// contains filtered or unexported fields
}

Repeat contains repeat fields for .proto file

type Val

type Val struct {
	CommonInfo
	// contains filtered or unexported fields
}

Val contains fields for .proto file

Jump to

Keyboard shortcuts

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