hugo: Index | Files

package codegen

import ""

Package codegen contains helpers for code generation.


Package Files


type Inspector Uses

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 Uses

func NewInspector(root string) *Inspector

NewInspector creates a new Inspector given a source root.

func (*Inspector) MethodsFromTypes Uses

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 Uses

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 Uses

func (m Method) Declaration(receiver string) string

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

func (Method) DeclarationNamed Uses

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 Uses

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

Delegate creates a delegate call string.

func (Method) String Uses

func (m Method) String() string

type Methods Uses

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 Uses

func (m Methods) Imports() []string

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

func (Methods) ToMarshalJSON Uses

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

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

Package codegen imports 12 packages (graph) and is imported by 7 packages. Updated 2019-08-20. Refresh now. Tools for package owners.