golang

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

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

Go to latest
Published: Jan 23, 2023 License: MIT Imports: 16 Imported by: 2

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 EnglishName

func EnglishName(name string) english.Name

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) (english.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 Name

type Name struct {
	English    english.Name
	IsExported bool
}

func (Name) String

func (n Name) String() string

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
	Fields   []Field // If struct

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

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

	IsIdent bool
	Ident   *Ident // If identifier

	Methods map[string]*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

type Workdir

type Workdir string

func SetupWorkdir

func SetupWorkdir(loc string) (Workdir, error)

func (Workdir) Build

func (dir Workdir) Build(path, output string) error

Build runs go build -o output target in the workdir.

func (Workdir) CloneGithubRepo

func (dir Workdir) CloneGithubRepo(org, repo string) error

CloneGithubRepo clones the given repo into the workdir at workdir/org/repo.

func (Workdir) ParsePackage

func (dir Workdir) ParsePackage(path string) (*Package, error)

func (Workdir) Pull

func (w Workdir) Pull(org, repo string) error

Pull pulls the latest changes from the remote for a given repo. If the repo is not cloned, it will be cloned.

Jump to

Keyboard shortcuts

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