parser

package
v0.0.0-...-19eb0a2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCheckTypeInvalid = errors.New("check type not support")
)
View Source
var (
	ErrIgnoreColumn = errors.New("ingore this column")
)

Functions

func FormatBool

func FormatBool(b bool) string

FormatBool returns "true" or "false" according to the value of b.

func LimitCheck

func LimitCheck(sheets []*XlsxSheet) (errs error)

func LoadXlsx

func LoadXlsx(fname string) (datas []*XlsxSheet, check []*XlsxCheckSheet, errs error)

LoadXlsx 加载数据

func LuaCheckFuncMax

func LuaCheckFuncMax(L *lua.LState) int

LuaCheckFuncMax 检测最大值上限

func LuaCheckFuncMin

func LuaCheckFuncMin(L *lua.LState) int

LuaCheckFuncMin 检测最小值下限

func LuaCheckFuncRange

func LuaCheckFuncRange(L *lua.LState) int

LuaCheckFuncRange 检测数值有效范围

func LuaCheckFuncValues

func LuaCheckFuncValues(L *lua.LState) int

LuaCheckFuncValues 有指定数据的检测

func LuaCheckTable

func LuaCheckTable(L *lua.LState, check *XlsxCheckSheet, innerErrors *[]error) (errs error)

func LuaHelperGetCheckList

func LuaHelperGetCheckList(L *lua.LState) *[]ValueCheck

LuaHelperGetCheckList lua注册辅助,获取checklist指针

func ParseBool

func ParseBool(str string) (bool, error)

func PrepareCheckTable

func PrepareCheckTable(errs *[]error) *lua.LState

func RegisterAutoType

func RegisterAutoType(check func(def string) Type)

RegisterAutoType 注册自动解析的类型

func RegisterCheck

func RegisterCheck(name string, f lua.LGFunction)

func RegisterDefaultChecker

func RegisterDefaultChecker()

func RegisterDefaultType

func RegisterDefaultType()

func RegisterType

func RegisterType(typ Type)

RegisterType 注册基础类型

func SetLuaCheckTable

func SetLuaCheckTable(L *lua.LState, table *XlsxSheet) (err error)

Types

type Array

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

Array 类型

func (*Array) Checkers

func (t *Array) Checkers() []ValueCheck

类型自带的检测

func (*Array) GoTypeName

func (t *Array) GoTypeName() (string, error)

func (*Array) Name

func (t *Array) Name() string

内置类型名

func (*Array) PBTypeName

func (t *Array) PBTypeName() (string, error)

func (*Array) Parse

func (t *Array) Parse(src string) (_ string, _ interface{}, errs error)

type ArrayType

type ArrayType interface {
	Element() Type
}

type Boolean

type Boolean struct{}

Boolean 布尔值类型

func (*Boolean) Checkers

func (*Boolean) Checkers() []ValueCheck

类型自带的检测

func (*Boolean) GoTypeName

func (*Boolean) GoTypeName() (string, error)

func (*Boolean) Name

func (*Boolean) Name() string

内置类型名

func (*Boolean) PBTypeName

func (*Boolean) PBTypeName() (string, error)

func (*Boolean) Parse

func (*Boolean) Parse(src string) (replace string, val interface{}, err error)

type ColumnType

type ColumnType struct {
	Type    Type   // 字段类型
	Name    string // 字段名
	Comment string // 注释信息

	Flags ExportTags // 字段标记
	// contains filtered or unexported fields
}

func NewField

func NewField(typ, name, commonts, filter string) (*ColumnType, error)

func (*ColumnType) EnableExport

func (filed *ColumnType) EnableExport(flag ExportTags) bool

EnableExport 是否允许导出

func (*ColumnType) Parse

func (field *ColumnType) Parse(cell string) (*XlsxCell, error)

Parse 解析单元格

type ExportTags

type ExportTags uint32

ExportTags export flag

const (
	ExportNone   ExportTags = 0x00
	ExportServer ExportTags = 0x01
	ExportClient ExportTags = 0x02
	ExportAll    ExportTags = 0x03
	ExportPM     ExportTags = 0x04
	ExportID     ExportTags = 0x08
)

func SplitFlags

func SplitFlags(raw string) (dst string, flags ExportTags, err error)

func (*ExportTags) All

func (f *ExportTags) All() bool

func (*ExportTags) Client

func (f *ExportTags) Client() bool

func (*ExportTags) ID

func (f *ExportTags) ID() bool

func (*ExportTags) Server

func (f *ExportTags) Server() bool

type Float

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

Float 数值类型

func NewFloat

func NewFloat(name string, cheker ...ValueCheck) *Float

func (*Float) Checkers

func (t *Float) Checkers() []ValueCheck

类型自带的检测

func (*Float) GoTypeName

func (t *Float) GoTypeName() (string, error)

func (*Float) Name

func (t *Float) Name() string

内置类型名

func (*Float) PBTypeName

func (t *Float) PBTypeName() (string, error)

func (*Float) Parse

func (*Float) Parse(src string) (replace string, val interface{}, err error)

type GoSupport

type GoSupport interface {
	GoTypeName() (string, error)
}

GoSupport 支持go语言接口

type Int

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

Int 数值类型

func NewInt

func NewInt(name string, cheker ...ValueCheck) *Int

func (*Int) Checkers

func (t *Int) Checkers() []ValueCheck

类型自带的检测

func (*Int) GoTypeName

func (t *Int) GoTypeName() (string, error)

func (*Int) Name

func (t *Int) Name() string

内置类型名

func (*Int) PBTypeName

func (t *Int) PBTypeName() (string, error)

func (*Int) Parse

func (*Int) Parse(src string) (replace string, val interface{}, err error)

type Map

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

Map 类型

func (*Map) Checkers

func (t *Map) Checkers() []ValueCheck

类型自带的检测

func (*Map) GoTypeName

func (t *Map) GoTypeName() (string, error)

func (*Map) Name

func (t *Map) Name() string

内置类型名

func (*Map) PBTypeName

func (t *Map) PBTypeName() (string, error)

func (*Map) Parse

func (t *Map) Parse(src string) (_ string, _ interface{}, errs error)

type MapType

type MapType interface {
	Key() Type
	Value() Type
}

type PBSupport

type PBSupport interface {
	PBTypeName() (string, error)
}

PBSupport 支持go语言接口

type String

type String struct{}

String 布尔值类型

func (*String) Checkers

func (*String) Checkers() []ValueCheck

类型自带的检测

func (*String) GoTypeName

func (*String) GoTypeName() (string, error)

func (*String) Name

func (*String) Name() string

内置类型名

func (*String) PBTypeName

func (*String) PBTypeName() (string, error)

func (*String) Parse

func (*String) Parse(src string) (replace string, val interface{}, err error)

type Type

type Type interface {
	// 解析数据
	Parse(src string) (replace string, val interface{}, err error)
	// 类型自带的检测
	Checkers() []ValueCheck
	// 内置类型名
	Name() string
}

Type xlsx支持的类型接口

func NewArray

func NewArray(def string) Type

func NewMap

func NewMap(def string) Type

func ParseType

func ParseType(def string) (Type, error)

ParseType 解析类型定义

type Uint

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

Uint 数值类型

func NewUint

func NewUint(name string, cheker ...ValueCheck) *Uint

func (*Uint) Checkers

func (t *Uint) Checkers() []ValueCheck

类型自带的检测

func (*Uint) GoTypeName

func (t *Uint) GoTypeName() (string, error)

func (*Uint) Name

func (t *Uint) Name() string

内置类型名

func (*Uint) PBTypeName

func (t *Uint) PBTypeName() (string, error)

func (*Uint) Parse

func (*Uint) Parse(src string) (replace string, val interface{}, err error)

type ValueCheck

type ValueCheck func(val interface{}) (err error)

数据检测

func ParseCheker

func ParseCheker(check string) (chekers []ValueCheck, err error)

type XlsxCell

type XlsxCell struct {
	// 原始数据
	Raw string
	//
	Value interface{}
}

type XlsxCheckSheet

type XlsxCheckSheet struct {
	FromFile   string
	Sheet      string
	LuaScripts map[string]string
}

XlsxCheckSheet lua数据检测

func ParseCheckXlsx

func ParseCheckXlsx(fromFile string, sheet *xlsx.Sheet) (data *XlsxCheckSheet, errs error)

ParseCheckXlsx 解析数据检测脚本表格(lua)

type XlsxSheet

type XlsxSheet struct {
	// sheet 名
	SheetName string
	// 生成结构体名称
	StructName string
	// 来源文件
	FromFile string
	// 字段及类型
	AllType []*ColumnType
	// 数据 索引分别是 行,列
	AllData [][]*XlsxCell
	// 单结构体标记
	KVFlag bool
	// sheet级标记
	Flag ExportTags
	// contains filtered or unexported fields
}

func ParseDataXlsx

func ParseDataXlsx(fromFile string, sheet *xlsx.Sheet, sheetName string, flags ExportTags) (data *XlsxSheet, errs error)

ParseDataXlsx 解析数据表格 数组或者map

func ParseKVXlsx

func ParseKVXlsx(fromFile string, sheet *xlsx.Sheet, sheetName string, flags ExportTags) (data *XlsxSheet, errs error)

ParseKVXlsx 解析结构体表格

func (*XlsxSheet) ClientData

func (sheet *XlsxSheet) ClientData() [][]*XlsxCell

func (*XlsxSheet) ClientType

func (sheet *XlsxSheet) ClientType() []*ColumnType

func (*XlsxSheet) EnableExport

func (sheet *XlsxSheet) EnableExport(flag ExportTags) bool

EnableExport 是否允许导出

func (*XlsxSheet) ExportData

func (sheet *XlsxSheet) ExportData(tag ExportTags) [][]*XlsxCell

func (*XlsxSheet) ExportType

func (sheet *XlsxSheet) ExportType(tag ExportTags) []*ColumnType

func (*XlsxSheet) IDTypes

func (sheet *XlsxSheet) IDTypes() []*ColumnType

func (*XlsxSheet) ServerData

func (sheet *XlsxSheet) ServerData() [][]*XlsxCell

func (*XlsxSheet) ServerType

func (sheet *XlsxSheet) ServerType() []*ColumnType

Jump to

Keyboard shortcuts

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