Documentation
¶
Index ¶
- Variables
- func ParseSheetIntoStructSlice[T any](cfg Config, opts ...ConfigOption) ([]T, error)
- func ParseSheetIntoStructs[T any](cfg Config, opts ...ConfigOption) (iter.Seq2[int, Result[T]], error)
- type Config
- type ConfigOption
- func WithAllowSkipColumns(allow bool) ConfigOption
- func WithAllowSkipFields(allow bool) ConfigOption
- func WithContext(ctx context.Context) ConfigOption
- func WithDatetimeFormats(formats ...string) ConfigOption
- func WithSheetName(name string) ConfigOption
- func WithSpreadsheetID(id string) ConfigOption
- func WithTagName(name string) ConfigOption
- type ConvertError
- type InvalidDateTimeFormatError
- type MappingError
- type Result
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoService is returned when no Google API service is registered to the Config. ErrNoService = errors.New("gsheets: no Google API service registered") // ErrNoSpreadSheetID is returned when no spreadsheet ID is provided to the parse call. ErrNoSpreadSheetID = errors.New("gsheets: no spreadsheet id provided") // ErrUnsupportedType is returned when the type of field is not supported. ErrUnsupportedType = errors.New("gsheets: unsupported type") // ErrNoMapping is returned when not a single field mapping is found. ErrNoMapping = errors.New("gsheets: no mapping found") // ErrFieldNotFoundInSheet is returned when a field is not found in the sheet. ErrFieldNotFoundInSheet = errors.New("gsheets: field not found in sheet") // ErrFieldNotFoundInStruct is returned when a field/column is not found in the struct. ErrFieldNotFoundInStruct = errors.New("gsheets: field not found in struct") )
Functions ¶
func ParseSheetIntoStructSlice ¶
func ParseSheetIntoStructSlice[T any](cfg Config, opts ...ConfigOption) ([]T, error)
ParseSheetIntoStructSlice parses a sheet page and returns a slice of structs with the give type. If an error occurs, the function will immediately return it.
func ParseSheetIntoStructs ¶
func ParseSheetIntoStructs[T any](cfg Config, opts ...ConfigOption) (iter.Seq2[int, Result[T]], error)
ParseSheetIntoStructs parses a sheet page and returns an iterator over the parsing Result. If an error occurs during validation or when fetching data, the function will return it. Parsing errors are returned as part of the Result, and can therefore be handled by the caller. The iterator will still proceed to the next row, if it isn't stopped.
Types ¶
type Config ¶
type Config struct { Service *sheets.Service // contains filtered or unexported fields }
Config holds the configuration for the Google Sheets parser.
func MakeConfig ¶
func MakeConfig(svc *sheets.Service, spreadsheetID string, opts ...ConfigOption) Config
MakeConfig creates a new Config with the given Google Sheets service and arbitrary options.
type ConfigOption ¶
type ConfigOption func(*config)
ConfigOption is a function allows to modify a Config.
func WithAllowSkipColumns ¶
func WithAllowSkipColumns(allow bool) ConfigOption
WithAllowSkipColumns allows to skip columns that cannot be mapped to a struct field. If this is set to false, an error will be raised.
func WithAllowSkipFields ¶
func WithAllowSkipFields(allow bool) ConfigOption
WithAllowSkipFields allows to skip fields that are not found in the sheet. If this is set to false, an error will be raised.
func WithContext ¶
func WithContext(ctx context.Context) ConfigOption
WithContext sets the given context for the Config. This context will be used for all API calls, and cancellation will be respected during iteration.
func WithDatetimeFormats ¶
func WithDatetimeFormats(formats ...string) ConfigOption
WithDatetimeFormats allows to define additional date-time formats to be recognized during the parsing.
func WithSheetName ¶
func WithSheetName(name string) ConfigOption
WithSheetName sets the sheet-name for the Config.
func WithSpreadsheetID ¶
func WithSpreadsheetID(id string) ConfigOption
WithSpreadsheetID sets the spreadsheet ID for the Config.
func WithTagName ¶
func WithTagName(name string) ConfigOption
WithTagName sets the tag-name to be looked at in the structs. This might come in handy if you have multiple structs with different tags, or another library also uses `gsheets:` as tag identifier.
type ConvertError ¶
ConvertError is returned when a conversion error occurs.
func (*ConvertError) Error ¶
func (e *ConvertError) Error() string
func (*ConvertError) Unwrap ¶
func (e *ConvertError) Unwrap() error
type InvalidDateTimeFormatError ¶
InvalidDateTimeFormatError is returned when an invalid datetime format is encountered.
func (*InvalidDateTimeFormatError) Error ¶
func (e *InvalidDateTimeFormatError) Error() string
type MappingError ¶
type MappingError struct { Sheet string Cell string Field string // contains filtered or unexported fields }
MappingError is returned when an error is encountered during the mapping.
func (*MappingError) Error ¶
func (e *MappingError) Error() string
func (*MappingError) Unwrap ¶
func (e *MappingError) Unwrap() error