genutil

package
v1.25.2 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalBuiltin

func MarshalBuiltin(kind schema.BuiltinKind, value *Statement) Code

MarshalBuiltin generates the code to marshal a builtin type. The resulting code if an expression of type string.

func MarshalBuiltinList

func MarshalBuiltinList(kind schema.BuiltinKind, value *Statement) Code

MarshalBuiltinList generates the code to marshal a list of builtins. The resulting code is an expression of type []string.

func Q

func Q(info *pkginfo.PkgDeclInfo) *Statement

Q returns a qualified name (using [jen.Qual]) for the given info.

func UnmarshallerTypeName

func UnmarshallerTypeName() *Statement

UnmarshallerTypeName returns a type expression for the etype.Unmarshaller type in the runtime, in the form "*etype.Unmarshaller".

Types

type Helper

type Helper struct {
	Errs *perr.List
}

func NewHelper

func NewHelper(errs *perr.List) *Helper

func (*Helper) Builtin

func (g *Helper) Builtin(pos gotoken.Pos, kind schema.BuiltinKind) *Statement

func (*Helper) GoToJen

func (g *Helper) GoToJen(pos gotoken.Pos, val any) *Statement

func (*Helper) Initialize

func (g *Helper) Initialize(typ schema.Type) *Statement

Initialize returns a jen expression for initializing the given type. If the type is a pointer type it returns new(Foo), and make(Foo) for slices and maps.

Certain types like function types and interfaces return "nil" as there is no canonical way to initialize them to a non-zero value.

func (*Helper) IsNotJSONEmpty added in v1.20.4

func (g *Helper) IsNotJSONEmpty(expr *Statement, typ schema.Type) *Statement

IsNotJSONEmpty returns a jen expression evaluating whether expr is not "empty". "Empty" is defined by the encoding/json package as: "false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string."

func (*Helper) NewTypeUnmarshaller

func (g *Helper) NewTypeUnmarshaller(objName string) *TypeUnmarshaller

func (*Helper) Type

func (g *Helper) Type(typ schema.Type) *Statement

Type generates a Go type from a schema type.

func (*Helper) TypeToString

func (g *Helper) TypeToString(typ schema.Type) string

TypeToString converts a schema.Type to a string.

func (*Helper) Zero

func (g *Helper) Zero(typ schema.Type) *Statement

Zero returns a jen expression representing the zero value for the given type. If the type is nil it returns "nil".

type TypeUnmarshaller

type TypeUnmarshaller struct {
	// contains filtered or unexported fields
}

func (*TypeUnmarshaller) Err

func (u *TypeUnmarshaller) Err() *Statement

func (*TypeUnmarshaller) HasError

func (u *TypeUnmarshaller) HasError() *Statement

func (*TypeUnmarshaller) IncNonEmpty added in v1.16.0

func (u *TypeUnmarshaller) IncNonEmpty() *Statement

IncNonEmpty returns a statement to increment the number of non-empty values the unmarshaller has processed.

func (*TypeUnmarshaller) Init

func (u *TypeUnmarshaller) Init() *Statement

func (*TypeUnmarshaller) NumNonEmptyValues

func (u *TypeUnmarshaller) NumNonEmptyValues() *Statement

NumNonEmptyValues returns an integer expression that reports the number of non-empty values the unmarshaller has processed.

func (*TypeUnmarshaller) ParseJSON

func (u *TypeUnmarshaller) ParseJSON(fieldName string, iteratorExpr *Statement, dstExpr *Statement) *Statement

ParseJSON returns an expression to parse json. It uses the iterator accessed through the given iteratorExpr to parse JSON into the given dstExpr. The dstExpr must be a pointer value. The field name is only used for error reporting.

func (*TypeUnmarshaller) ReadBody

func (u *TypeUnmarshaller) ReadBody(bodyExpr *Statement) *Statement

ReadBody returns an expression to read the full request body into a []byte.

func (*TypeUnmarshaller) UnmarshalBuiltin

func (u *TypeUnmarshaller) UnmarshalBuiltin(kind schema.BuiltinKind, fieldName string, value *Statement, required bool) *Statement

func (*TypeUnmarshaller) UnmarshalBuiltinList

func (u *TypeUnmarshaller) UnmarshalBuiltinList(kind schema.BuiltinKind, fieldName string, value *Statement, required bool) *Statement

UnmarshalBuiltinList unmarshals a list of builtins.

func (*TypeUnmarshaller) UnmarshalSingleOrList

func (u *TypeUnmarshaller) UnmarshalSingleOrList(typ schema.Type, fieldName string, singleValue, listOfValues *Statement, required bool) *Statement

UnmarshalSingleOrList returns the code to unmarshal a supported type. The type must be a builtin or a list of builtins.

Jump to

Keyboard shortcuts

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