gocodegen

package
v1.29.5 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package gocodegen contains shared code used for generating Go code by both the compilers code generator, and the CLI's client generator.

Index

Constants

View Source
const UnknownPkgPath = "__unknown_path__"

Variables

This section is empty.

Functions

func ConvertBuiltInSchemaToJenType added in v1.8.0

func ConvertBuiltInSchemaToJenType(builtin schema.Builtin) *Statement

func ConvertSchemaToJenType added in v1.8.0

func ConvertSchemaToJenType(typ *schema.Type, md *meta.Data) *Statement

ConvertSchemaToJenType converts a schema.Type to a Jen statement which represents the type

func ConvertSchemaTypeToString added in v1.8.0

func ConvertSchemaTypeToString(typ *schema.Type, md *meta.Data) string

ConvertSchemaTypeToString converts a schema.Type to a string that can be used in a log output which can be increbily useful for debugging if the parser as generated the expected Schema protobuf from the original Go code

Types

type MarshallingCodeGenerator

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

MarshallingCodeGenerator is used to generate a structure has methods for decoding various types, collecting the errors. It will only generate methods required for the given types.

func NewMarshallingCodeGenerator

func NewMarshallingCodeGenerator(pkgPath, structName string, forClientGen bool) *MarshallingCodeGenerator

func (*MarshallingCodeGenerator) GenerateAll added in v1.4.0

func (g *MarshallingCodeGenerator) GenerateAll()

GenerateAll causes the generator to generate all possible methods.

func (*MarshallingCodeGenerator) NewPossibleInstance

func (g *MarshallingCodeGenerator) NewPossibleInstance(instanceName string) *MarshallingCodeWrapper

NewPossibleInstance Creates a statement to initialise a new encoding instance.

Use the returned wrapper to convert FromStrings to the target types, adding any code you are generating to the wrapper using Add. Once you've finished generating all the code which may need type conversion with that _instance_ of the deserializer, call Finalize to generate the code full code including error handling.

Once you've finished writing the whole app with all the code which uses this generator call WriteToFile to write the supporting struct and methods to the given file

func (*MarshallingCodeGenerator) WriteToFile

func (g *MarshallingCodeGenerator) WriteToFile(f *File)

WriteToFile writes the full encoder type into the given file.

type MarshallingCodeWrapper

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

MarshallingCodeWrapper is returned by NewPossibleInstance and tracks usage within a block

func (*MarshallingCodeWrapper) Add

func (w *MarshallingCodeWrapper) Add(c ...Code)

Add adds code into the wrapped block

func (*MarshallingCodeWrapper) Body

func (w *MarshallingCodeWrapper) Body(getBody Code) Code

func (*MarshallingCodeWrapper) EndBlock added in v1.3.0

func (w *MarshallingCodeWrapper) EndBlock(endBlock ...Code)

EndBlock adds custom logic after the error block

func (*MarshallingCodeWrapper) Finalize

func (w *MarshallingCodeWrapper) Finalize(ifErrorBlock ...Code) []Code

Finalize returns the final code block including all wrapped code

func (*MarshallingCodeWrapper) FromJSON

func (w *MarshallingCodeWrapper) FromJSON(targetType *schema.Type, fieldName string, iterName string, dst Code) (code Code, err error)

func (*MarshallingCodeWrapper) FromString

func (w *MarshallingCodeWrapper) FromString(targetType *schema.Type, fieldName string, getAsString Code, getAsStringSlice Code, required bool) (code Code, err error)

FromString will return a call to a decoder method

func (*MarshallingCodeWrapper) FromStringToBuiltin

func (w *MarshallingCodeWrapper) FromStringToBuiltin(builtin schema.Builtin, fieldName string, getAsString Code, required bool) (code Code, err error)

FromStringToBuiltin will return either the original string or a call to the encoder

func (*MarshallingCodeWrapper) LastError

func (w *MarshallingCodeWrapper) LastError() Code

func (*MarshallingCodeWrapper) ToString

func (w *MarshallingCodeWrapper) ToString(sourceType *schema.Type, sourceValue Code) (code Code, err error)

ToString will return either the original string or a call to the encoder

func (*MarshallingCodeWrapper) ToStringSlice

func (w *MarshallingCodeWrapper) ToStringSlice(sourceType *schema.Type, sourceValue Code) (code Code, err error)

ToStringSlice will return either the original string or a call to the encoder

func (*MarshallingCodeWrapper) WithFunc added in v1.4.0

func (w *MarshallingCodeWrapper) WithFunc(body func(*Group), errBlock func(*Group)) []Code

Jump to

Keyboard shortcuts

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