golang

package module
v0.0.0-...-0235920 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMultiplePackages = errors.New("multiple packages found")
View Source
var ErrMultipleReceivers = errors.New("expected method to have one receiver")

Functions

func DefaultValue

func DefaultValue(id Ident) string

func FilterTests

func FilterTests(fi fs.FileInfo) bool

func GenerateCLI

func GenerateCLI(srcDir, pkg, funcName, outFile string) error

GenerateCLI geneates a simple Go CLI app that only calls a single func. The resulting command has no arguments. It reads function input from stdin in JSON format and writes the result to stdout in JSON format.

func GenerateHTTPHandler

func GenerateHTTPHandler(srcDir, pkg, typeName, outFile string) error

GenerateHandler generates ServeHTTP methods for each type declaration in the file. Experimental.

func ParseName

func ParseName(name string) (*nameconv.Name, error)

func RunGoimports

func RunGoimports(path string) error

Types

type Field

type Field struct {
	Name string
	Type *Type
}

type FuncSignature

type FuncSignature struct {
	Inputs  []Field
	Outputs []Field
}

func ReadFuncSignature

func ReadFuncSignature(srcDir, pkg, funcName string) (*FuncSignature, error)

ReadFuncSignature reads the function signature of a function in a package. srcDir should be a directory with all your source code. Packages in srcDir should be in the format "github.com/username/repo".

type Ident

type Ident struct {
	From string
	Name string
}

func BuildIdent

func BuildIdent(currentPkg string, importMap ImportMap, expr ast.Expr) (*Ident, error)

func (Ident) String

func (i Ident) String() string

type ImportMap

type ImportMap map[string]string

ImportMap maps package paths to local variable names.

func BuildImportMap

func BuildImportMap(f *ast.File) (ImportMap, error)

func (ImportMap) AddPackage

func (i ImportMap) AddPackage(pkg string) string

AddPackage adds the given package path to the import map. It will ensure there are no naming conflicts by appending as many underscores as necessary to the end of the variable name.

func (ImportMap) Resolve

func (i ImportMap) Resolve(pkg string) (string, bool)

Resolve will return the associate variable name with an imported package.

func (ImportMap) Write

func (i ImportMap) Write(w io.Writer) error

Write will write the import map in Go to w.

type Package

type Package struct {
	Name  string
	Types map[string]*Type
	Funcs map[string]*ast.FuncDecl
}

func ParsePackage

func ParsePackage(srcDir, pkgName string) (*Package, error)

type Type

type Type struct {
	IsStruct bool
	// If struct
	Fields []Field

	IsMap bool
	// If map
	KeyType   *Type
	ValueType *Type

	IsPointer bool
	IsArray   bool
	// If pointer or array
	BaseType *Type

	IsIdent bool
	// If identifier
	Ident *Ident

	Methods []*ast.FuncDecl
}

func BuildType

func BuildType(currPkg string, importMap ImportMap, t ast.Expr) (*Type, error)

func (*Type) Packages

func (t *Type) Packages() []string

func (*Type) Write

func (t *Type) Write(io.Writer) error

Jump to

Keyboard shortcuts

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