inject

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrUnsupportedGoyaveVersion returned when using NewInjector
	// with a Goyave project using an outdated version of the framework
	ErrUnsupportedGoyaveVersion = fmt.Errorf("Unsupported Goyave version. Minimum version: %s", minimumGoyaveVersion.Original())
)

Functions

func DBClear

func DBClear(directory string) (func() error, error)

DBClear generate and return database clear function.

func FindExportedFunctions

func FindExportedFunctions(directory string) ([]string, error)

FindExportedFunctions find all exported functions in given directory.

func GetBlankImports

func GetBlankImports(directory string) ([]string, error)

GetBlankImports returns all blank imports ("_") found in go files in the given directory. Doesn't check sub-directories.

func ImportToString

func ImportToString(i *ast.ImportSpec) string

ImportToString convert *ast.ImportSpec to a valid import statement (without prepending "import "), supporting aliases. If the given *ast.ImportSpec is nil, an empty string is returned.

func Migrate

func Migrate(directory string) (func() error, error)

Migrate generate and return database migration function.

func OpenAPI3Generator

func OpenAPI3Generator(directory string) (func() ([]byte, error), error)

OpenAPI3Generator injects openapi3 generator into given Goyave project. Returns the injected function.

func Seeder

func Seeder(directory string, seeders []string) (func() error, error)

Seeder generate and return database seed function.

Types

type Dependency added in v0.2.2

type Dependency struct {
	// Name of the dependency (e.g.: "goyave.dev/goyave/v4")
	Name string

	// Version of the dependency (e.g.: "v4.0.0"). Leave empty for latest.
	Version string
}

Dependency a library that needs to be imported for the planned injection.

type FunctionCall

type FunctionCall struct {
	Package *ast.ImportSpec
	Value   string
}

FunctionCall is a string representation of a function call or reference with its matching import. Doesn't support functions with parameters.

func FindRouteRegistrer

func FindRouteRegistrer(directory string, goyaveImportPath string) (*FunctionCall, error)

FindRouteRegistrer tries to find the route registrer function from Go files inside the given directory using the Go AST. Sub-directories are not checked. If `goyave.Start()` is found, then the parameter passed to it is assumed to be the main route registrer function. Import aliases are supported. To properly identify `goyave.Start()`, this function needs the Goyave import path specified in `go.mod`.

type Injector

type Injector struct {
	ModFile          *modfile.File
	GoyaveImportPath string
	GoyaveVersion    *semver.Version

	// StubName the path to the embedded stub used for
	// the temporary source file generation.
	StubName string
	// StubData the data to inject into the stub.
	StubData stub.Data

	// Dependencies list of libraries that need to be imported
	// for the planned injection. These libraries will be added
	// automatically using "go get" and removed after the build is complete.
	Dependencies []Dependency
	// contains filtered or unexported fields
}

Injector code injector for Goyave projects. Builds a temporary source file at the project's root, build the project in plugin mode and return a Plugin instance.

func NewInjector

func NewInjector(directory string) (*Injector, error)

NewInjector create a new injector for the project in the given directory. Can return an error if the given directory is not a Goyave project or its version is not supported for injection.

func (*Injector) Inject

func (i *Injector) Inject() (*plugin.Plugin, error)

Inject writes temporary source file, compiles plugin, loads it and cleans temporary source file and compiled plugin.

Jump to

Keyboard shortcuts

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