gocodegen

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: MPL-2.0 Imports: 4 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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(structName string, forClientGen bool) *MarshallingCodeGenerator

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

Jump to

Keyboard shortcuts

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