Version: v0.88.1 Latest Latest

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

Go to latest
Published: Sep 4, 2021 License: Apache-2.0 Imports: 12 Imported by: 0



Package codegen contains helpers for code generation.



This section is empty.


This section is empty.


This section is empty.


type Inspector

type Inspector struct {
	ProjectRootDir string
	// contains filtered or unexported fields

Inspector provides methods to help code generation. It uses a combination of reflection and source code AST to do the heavy lifting.

func NewInspector

func NewInspector(root string) *Inspector

NewInspector creates a new Inspector given a source root.

func (*Inspector) MethodsFromTypes

func (c *Inspector) MethodsFromTypes(include []reflect.Type, exclude []reflect.Type) Methods

MethodsFromTypes create a method set from the include slice, excluding any method in exclude.

type Method

type Method struct {
	// The interface we extracted this method from.
	Owner reflect.Type

	// String version of the above, on the form PACKAGE.NAME, e.g.
	// page.Page
	OwnerName string

	// Method name.
	Name string

	// Imports needed to satisfy the method signature.
	Imports []string

	// Argument types, including any package prefix, e.g. string, int, interface{},
	// net.Url
	In []string

	// Return types.
	Out []string

Method holds enough information about it to recreate it.

func (Method) Declaration

func (m Method) Declaration(receiver string) string

Declaration creates a method declaration (without any body) for the given receiver.

func (Method) DeclarationNamed

func (m Method) DeclarationNamed(receiver string) string

DeclarationNamed creates a method declaration (without any body) for the given receiver with named return values.

func (Method) Delegate

func (m Method) Delegate(receiver, delegate string) string

Delegate creates a delegate call string.

func (Method) String

func (m Method) String() string

type Methods

type Methods []Method

Methods represents a list of methods for one or more interfaces. The order matches the defined order in their source file(s).

func (Methods) Imports

func (m Methods) Imports() []string

Imports returns a sorted list of package imports needed to satisfy the signatures of all methods.

func (Methods) ToMarshalJSON

func (m Methods) ToMarshalJSON(receiver, pkgPath string, excludes ...string) (string, []string)

ToMarshalJSON creates a MarshalJSON method for these methods. Any method name matching any of the regexps in excludes will be ignored.

Source Files

Jump to

Keyboard shortcuts

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