pkg

package
v0.0.0-...-89768cc Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjustTypes

func AdjustTypes(file *ast.File, registeredTypeCheckers []TypeDeterminationFunction, skipPreviouslyFailed bool) error

AdjustTypes Goes through all fields and looks at the json2go Tag, to determine if there's a better suiting type for the seen float and string values. Floats which could be represented as an int, are changed to int Strings which could be represented as UUID are change into uuid.UUID Strings which could be represented as time, are changed into time.Time

func CombineStructsOfFile

func CombineStructsOfFile(file, file1 *ast.File) (*ast.File, error)

func GenerateCodeIntoDecl

func GenerateCodeIntoDecl(jsonData []byte, decls []ast.Decl, structName string) ([]ast.Decl, error)

func GenerateJsonMarshall

func GenerateJsonMarshall(file *ast.File) error

func GenerateJsonUnmarshall

func GenerateJsonUnmarshall(file *ast.File) error

func SetMixedTypes

func SetMixedTypes(tag *ast.BasicLit) (*ast.BasicLit, error)

Types

type IntTypeChecker

type IntTypeChecker struct{}

func (*IntTypeChecker) CouldTypeBeApplied

func (i *IntTypeChecker) CouldTypeBeApplied(seenValues map[string]string) bool

func (*IntTypeChecker) GenerateFromTypeFunction

func (i *IntTypeChecker) GenerateFromTypeFunction(functionScaffold *ast.FuncDecl) (*ast.FuncDecl, error)

func (*IntTypeChecker) GenerateToTypeFunction

func (i *IntTypeChecker) GenerateToTypeFunction(functionScaffold *ast.FuncDecl) (*ast.FuncDecl, error)

func (*IntTypeChecker) GetName

func (i *IntTypeChecker) GetName() string

func (*IntTypeChecker) GetRequiredImports

func (i *IntTypeChecker) GetRequiredImports() []string

func (*IntTypeChecker) GetType

func (i *IntTypeChecker) GetType() ast.Expr

func (*IntTypeChecker) SetFile

func (i *IntTypeChecker) SetFile(_ *ast.File)

type ParseFunctions

type ParseFunctions struct {
	FromTypeParseFunction string `json:"fromTypeParseFunction,omitempty"`
	ToTypeParseFunction   string `json:"toTypeParseFunction,omitempty"`
}

type Tag

type Tag struct {
	// SeenValues Holds all seem field values and their corresponding type
	SeenValues map[string]string `json:"seenValues,omitempty"`
	// CheckedNonMatchingTypes Is used to store a map of non-matching types referencing the time of storage as unix timestamp.
	// This is useful when working with a lot of input data, and the seen values becomes to big
	CheckedNonMatchingTypes map[string]int64 `json:"checkedNonMatchingTypes,omitempty"`
	// ParseFunctions Holds the names of the parse functions generated by TypeDeterminationFunction
	ParseFunctions *ParseFunctions `json:"parseFunctions,omitempty"`
	// BaseType The type before it was modified from a TypeDeterminationFunction
	BaseType *string `json:"baseType,omitempty"`
	// MixedTypes is set, whenever an array whit mixed types is encountered
	MixedTypes bool `json:"mixedTypes,omitempty"`
	// LastSeenTimestamp Unix timestamp. Is updated whenever a value is seen
	LastSeenTimestamp int64 `json:"lastSeenTimestamp"`
}

func GetJson2GoTag

func GetJson2GoTag(tag string) (*Tag, error)

func GetJson2GoTagFromBasicLit

func GetJson2GoTagFromBasicLit(tag *ast.BasicLit) (*Tag, error)

func (*Tag) AppendToTag

func (j *Tag) AppendToTag(tag *ast.BasicLit) (*ast.BasicLit, error)

func (*Tag) Combine

func (j *Tag) Combine(j1 *Tag) (*Tag, error)

func (*Tag) ToBasicLit

func (j *Tag) ToBasicLit() (*ast.BasicLit, error)

func (*Tag) ToTagString

func (j *Tag) ToTagString() (string, error)

func (*Tag) ToTagValue

func (j *Tag) ToTagValue() (string, error)

type TagCombiner

type TagCombiner struct{}

func (*TagCombiner) Combine

func (j *TagCombiner) Combine(values []string) (string, error)

type TimeTypeChecker

type TimeTypeChecker struct {
	// IgnoreYearOnlyStrings Set to ignore strings that consist only of a year such as 3294. Most often, they're
	// integers not years!
	IgnoreYearOnlyStrings bool
	// contains filtered or unexported fields
}

func (*TimeTypeChecker) CouldTypeBeApplied

func (t *TimeTypeChecker) CouldTypeBeApplied(seenValues map[string]string) bool

func (*TimeTypeChecker) GenerateFromTypeFunction

func (t *TimeTypeChecker) GenerateFromTypeFunction(functionScaffold *ast.FuncDecl) (*ast.FuncDecl, error)

func (*TimeTypeChecker) GenerateToTypeFunction

func (t *TimeTypeChecker) GenerateToTypeFunction(functionScaffold *ast.FuncDecl) (*ast.FuncDecl, error)

func (*TimeTypeChecker) GetName

func (t *TimeTypeChecker) GetName() string

func (*TimeTypeChecker) GetRequiredImports

func (t *TimeTypeChecker) GetRequiredImports() []string

func (*TimeTypeChecker) GetType

func (t *TimeTypeChecker) GetType() ast.Expr

func (*TimeTypeChecker) SetFile

func (t *TimeTypeChecker) SetFile(_ *ast.File)

type TypeDeterminationFunction

type TypeDeterminationFunction interface {
	CouldTypeBeApplied(seenValues map[string]string) bool
	GetType() ast.Expr
	GenerateFromTypeFunction(functionScaffold *ast.FuncDecl) (*ast.FuncDecl, error)
	GenerateToTypeFunction(functionScaffold *ast.FuncDecl) (*ast.FuncDecl, error)
	GetRequiredImports() []string
	SetFile(file *ast.File)
	GetName() string
}

type UUIDTypeChecker

type UUIDTypeChecker struct{}

func (*UUIDTypeChecker) CouldTypeBeApplied

func (u *UUIDTypeChecker) CouldTypeBeApplied(seenValues map[string]string) bool

func (*UUIDTypeChecker) GenerateFromTypeFunction

func (u *UUIDTypeChecker) GenerateFromTypeFunction(functionScaffold *ast.FuncDecl) (*ast.FuncDecl, error)

func (*UUIDTypeChecker) GenerateToTypeFunction

func (u *UUIDTypeChecker) GenerateToTypeFunction(functionScaffold *ast.FuncDecl) (*ast.FuncDecl, error)

func (*UUIDTypeChecker) GetName

func (u *UUIDTypeChecker) GetName() string

func (*UUIDTypeChecker) GetRequiredImports

func (u *UUIDTypeChecker) GetRequiredImports() []string

func (*UUIDTypeChecker) GetType

func (u *UUIDTypeChecker) GetType() ast.Expr

func (*UUIDTypeChecker) SetFile

func (u *UUIDTypeChecker) SetFile(_ *ast.File)

Jump to

Keyboard shortcuts

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