typemagic

package
v0.0.0-...-280a614 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SheetTag = "sheet"

	SheetTagOptionUID           = "uid"
	SheetTagOptionReadOnly      = "readonly"
	SheetTagOptionTrueRepr      = "true="
	SheetTagOptionFalseRepr     = "false="
	SheetTagOptionUnknownIsTrue = "utrue"
)

Variables

This section is empty.

Functions

func DumpCols

func DumpCols(item interface{}) column.Cols

DumpCols returns column.Cols that are used for this type (regardless if the column has a valid value or not)

func DumpStruct

func DumpStruct(item interface{}, omitReadOnly bool) map[string]string

DumpStruct dumps the structure into a rowData map based on the sheet:"..." struct tag. It can omit fields marked as read-only The uid field is not read-only by default, so if you want to omit it from the dump, you must mark it as read-only in the struct tag.

func DumpUID

func DumpUID(item interface{}) string

DumpUID extracts the UID value from the struct, if it is not configured it will use the left-most value, it dumps the value even if the uid col is marked read-only

func DumpUIDCol

func DumpUIDCol(item interface{}) string

DumpUIDCol is the same as DumpUID but with the column itself

func LoadIntoStruct

func LoadIntoStruct(data map[string]string, item interface{}) error

LoadIntoStruct returns an error only if the supplied data (coming from sheets) is not valid for the type in the struct. If the struct itself has issues, it will panic as ususal.

Types

type BoolRepresentation

type BoolRepresentation struct {
	True  string
	False string

	// Unknown represents the default value to be used, when it can not be decided
	Unknown bool
}

func (BoolRepresentation) Represent

func (br BoolRepresentation) Represent(val bool) string

func (BoolRepresentation) UnRepresent

func (br BoolRepresentation) UnRepresent(val string) bool

type Tag

type Tag struct {
	Column string
	IsUID  bool

	// IsReadOnly is in the context of the sheet, in other words, if this is set to true, the value will be read from the sheet, but never written to the sheet
	IsReadOnly         bool
	BoolRepresentation BoolRepresentation
}

func NewDefaultTag

func NewDefaultTag() Tag

func ParseTagValString

func ParseTagValString(tagVal string) Tag

func (Tag) HasColumn

func (t Tag) HasColumn() bool

Jump to

Keyboard shortcuts

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