Documentation
¶
Index ¶
- Constants
- type CsvInterface
- type CsvOptions
- type ExcelError
- type ExcelHeader
- type ExcelInput
- type ExcelInterface
- type ExcelOption
- type ExcelOptions
- type ExcelPoint
- type ExcelResult
- type ExcelResultData
- type ExcelResultDetails
- type ExcelResultHeader
- type Filter
- type JsonInterface
- type JsonOptions
- type Mapper
- type MapperV2
- type MapperYAxis
- type Options
- type Parser
- type Transformer
Constants ¶
View Source
const ( ExcelTypeSow = "sowexcel" ExcelTypePartialHarvest = "partialharvestexcel" ExcelTypeFinalHarvest = "finalharvestexcel" ExcelTypeDailyMonitoring = "dailymonitoringexcel" ExcelTypeSampling = "samplingexcel" ExcelTypeProductionPlan = "productionplanexcel" ExcelTypeFarmTechnician = "farmtechnicianexcel" ExcelTypeLabAnalyst = "labanalystexcel" ExcelTypeOrderBulkAquaCheck = "bulkorderaquacheck" ExcelTypeHealthIndex = "healthindexexcel" MetricName = "metric" ParsingErrMessage = "err:%+v mapper:%+v row:%d column: %d " ExcelTypeDynamicParser = "dynamic" SheetIndexRegex = `^([a-zA-Z\d]+)(.*)$` )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CsvInterface ¶
type CsvInterface interface {
SetOptionsRead(opt CsvOptions)
SetOptionsWrite(opt CsvOptions)
Marshal(orig interface{}) ([]byte, error)
MarshalWithoutHeaders(orig interface{}) ([]byte, error)
Unmarshal(blob []byte, dest interface{}) error
}
type CsvOptions ¶
type ExcelError ¶
type ExcelError []struct {
RowNum int
ColNum int
Value string // Old Value
Position string // "A1, B2, C3"
Message string
}
TODO: implemented on one template in curent service, later will be moved here
type ExcelHeader ¶
type ExcelInput ¶
ExcelInput is used as the structure to generate new excel file
type ExcelInterface ¶
type ExcelInterface interface {
// General Excel
Unmarshal(ctx context.Context, blob []byte) ([]map[string]string, error)
// Opiniated Excel
UnmarshalTransform(ctx context.Context, blob []byte, t Transformer) (ExcelResult, error)
UnmarshalTransformV2(ctx context.Context, blob []byte, t Transformer) (ExcelResult, error)
Validate(ctx context.Context, blob []byte, t Transformer) error
UnmarshalWithAxis(ctx context.Context, blob []byte, t Transformer) (ExcelResult, error)
UnmarshalTransformMultipleSheet(ctx context.Context, blob []byte, opt ExcelOption) (map[string]ExcelResult, error)
UnmarshalTransformMultipleSheetV2(ctx context.Context, blob []byte, opt ExcelOption) (map[string]ExcelResult, error)
UnmarshalTransformYAxis(ctx context.Context, blob []byte, t Transformer) (ExcelResult, error)
// Generate excel file
Marshal(ctx context.Context, input []ExcelInput, pathToFile string) error
WriteReader(ctx context.Context, blob []byte, ioReader io.Writer) error
InjectValue(ctx context.Context, blob []byte, sheetName string, values map[string]interface{}) ([]byte, error)
}
type ExcelOption ¶
type ExcelOption struct {
Type string `json:"type"`
Version string `json:"version"`
Parser Transformer `json:"parser"`
Parsers []Transformer `json:"parsers"`
ParserMap map[string]Transformer
}
type ExcelOptions ¶
type ExcelOptions map[string]ExcelOption
Note For next iteration parse column dynamically, read from column name and automatically map it
type ExcelPoint ¶
func EmptyRow ¶
func EmptyRow(nCol int) []ExcelPoint
type ExcelResult ¶
type ExcelResult struct {
Header ExcelResultHeader
Data []ExcelResultData
Details []ExcelResultDetails
}
type ExcelResultData ¶
type ExcelResultData map[string]interface{}
type ExcelResultDetails ¶
type ExcelResultDetails map[string]ExcelPoint
type ExcelResultHeader ¶
type ExcelResultHeader map[string]ExcelHeader
type JsonInterface ¶
type JsonInterface interface {
// Marshal go structs into bytes
Marshal(orig interface{}) ([]byte, error)
// Marshal go structs into bytes and validates returned bytes
MarshalWithSchemaValidation(sch string, orig interface{}) ([]byte, error)
// Unmarshal bytes into go structs
Unmarshal(blob []byte, dest interface{}) error
// Validates input bytes and Unmarshal
UnmarshalWithSchemaValidation(sch string, blob []byte, dest interface{}) error
}
type JsonOptions ¶
type JsonOptions struct {
Config jsonConfig
IndentionStep int
MarshalFloatWith6Digits bool
EscapeHTML bool
SortMapKeys bool
UseNumber bool
DisallowUnknownFields bool
TagKey string
OnlyTaggedField bool
ValidateJSONRawMessage bool
ObjectFieldMustBeSimpleString bool
CaseSensitive bool
// Schema contains schema definitions with key as schema name and value as source path
// schema sources can be file or URL. Schema definition will be iniatialized during
// JSON parser object initialization.
Schema map[string]string
}
type Mapper ¶
type Mapper struct {
Name string
ColNum int
Type string
Relation string
Axis string
RelationMap map[string]int64
}
func (*Mapper) ParseString ¶
type MapperV2 ¶
type MapperV2 struct {
Name string
Type string
Relation string
RelationMap map[string]int64
Multiple bool
MultiColumn bool
FilterRegex string
Mappers []Mapper
}
func (MapperV2) ParseString ¶
func (MapperV2) ParseStruct ¶
func (m MapperV2) ParseStruct(name string, input []ExcelPoint) (interface{}, error)
type MapperYAxis ¶
type Options ¶
type Options struct {
JsonOptions JsonOptions
CsvOptions CsvOptions
ExcelOptions ExcelOptions
}
type Parser ¶
type Parser interface {
JsonParser() JsonInterface
CsvParser() CsvInterface
ExcelParser() ExcelInterface
}
type Transformer ¶
type Transformer struct {
Name string
SheetType string
SheetName string
SheetRegex string
SheetSeparators string
SlicerInitialSkipRows int
SlicerInitialSkipCols int
SlicerNumRows int
SlicerNumCols int
IsDynamicHeader bool
Filters []Filter
Mappers []Mapper // Beware it's not exactly same number with the excel col number
MappersV2 map[string]MapperV2
MapperYAxis MapperYAxis
}
Click to show internal directories.
Click to hide internal directories.