marshalling

package
v0.0.0-...-33be302 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(expr ...Expr) (string, error)

func Marshal

func Marshal(ctx context.Context, v cue.Value, g Generator) (string, error)

Types

type Expr

type Expr interface {
	fmt.Stringer
}

Expr represents an expression in any language, used to construct the generated type.

type Generator

type Generator interface {
	// AST is the entrypoint when parsing any AST.  This delegates
	// to the specific functions below.
	//
	// It is given the context, the current AST to generate an expr from,
	// plus all parsed AST items and all currently generated Exprs
	AST(context.Context, []ParsedAST) ([]Expr, error)
}

type Lit

type Lit struct {
	Value string
}

Lit represents a literal string value, which is returned as-is.

func (Lit) String

func (l Lit) String() string

String fulfils the Expr interface, returning the string value.

type ParsedAST

type ParsedAST interface {
	// Kind represents the AST kind that the parsed AST represents.
	Kind() ParsedKind
	// name returns the name for the field, if specified.
	Name() string
	// SetDefault sets the default value, if found.
	SetDefault(to interface{})
}

ParsedAST is an interface which each parsed AST fulfills. This lets us specify an interface for eg. struct or enum member values.

func Parse

func Parse(ctx context.Context, v cue.Value) ([]ParsedAST, error)

Parse walks through a cue value, typically from a cue.Instance, calling the parsing the type definitions into our interim AST. The interim AST makes it much easier to generate basic types in many languages.

type ParsedArray

type ParsedArray struct {
	Members  []ParsedAST
	Default  interface{}
	Optional bool
	// contains filtered or unexported fields
}

ParsedArray represents an array type sepcified within Cue.

A Cue array can contain many different types; it is not constrained to storing a single type. Due to this, we store all available parsed types within the Types field.

func (ParsedArray) Kind

func (ParsedArray) Kind() ParsedKind

func (ParsedArray) Name

func (p ParsedArray) Name() string

func (*ParsedArray) SetDefault

func (p *ParsedArray) SetDefault(to interface{})

type ParsedEnum

type ParsedEnum struct {
	Members []ParsedAST
	Default interface{}
	// contains filtered or unexported fields
}

func (ParsedEnum) Kind

func (ParsedEnum) Kind() ParsedKind

func (ParsedEnum) Name

func (p ParsedEnum) Name() string

func (*ParsedEnum) SetDefault

func (p *ParsedEnum) SetDefault(to interface{})

type ParsedIdent

type ParsedIdent struct {

	// Type represnets the ast Ident that was parsed.
	Ident *ast.Ident

	// Default represents the default value, if any.
	Default interface{}
	// contains filtered or unexported fields
}

ParsedIdent represents a single scalar type, eg. a string or a number

func (ParsedIdent) Kind

func (ParsedIdent) Kind() ParsedKind

func (ParsedIdent) Name

func (p ParsedIdent) Name() string

func (*ParsedIdent) SetDefault

func (p *ParsedIdent) SetDefault(to interface{})

type ParsedKind

type ParsedKind int
const (
	KindNone ParsedKind = iota
	KindEnum
	KindStruct
	KindArray
	// KindIdent represents a single basic type
	KindIdent
	// KindScalar represents a single basic value
	KindScalar
)

type ParsedScalar

type ParsedScalar struct {
	Value    interface{}
	Default  interface{}
	Optional bool
	// contains filtered or unexported fields
}

ParsedScalar represents a single concrete scalar value, eg. a string instance "foo" or a number instance 42.

func (ParsedScalar) Kind

func (ParsedScalar) Kind() ParsedKind

func (ParsedScalar) Name

func (p ParsedScalar) Name() string

func (*ParsedScalar) SetDefault

func (*ParsedScalar) SetDefault(to interface{})

SetDefault is a no-op with scalars, as they're concrete.

type ParsedStruct

type ParsedStruct struct {
	Members []*ParsedStructField
	Default interface{}
	// contains filtered or unexported fields
}

func (ParsedStruct) Kind

func (ParsedStruct) Kind() ParsedKind

func (ParsedStruct) Name

func (p ParsedStruct) Name() string

func (*ParsedStruct) SetDefault

func (p *ParsedStruct) SetDefault(to interface{})

type ParsedStructField

type ParsedStructField struct {
	ParsedAST
	Optional bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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