Documentation ¶
Index ¶
- Variables
- func DBClear(directory string) (func() error, error)
- func FindExportedFunctions(directory string) ([]string, error)
- func GetBlankImports(directory string) ([]string, error)
- func ImportToString(i *ast.ImportSpec) string
- func Migrate(directory string) (func() error, error)
- func OpenAPI3Generator(directory string) (func() ([]byte, error), error)
- func Seeder(directory string, seeders []string) (func() error, error)
- type Dependency
- type FunctionCall
- type Injector
Constants ¶
This section is empty.
Variables ¶
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 FindExportedFunctions ¶
FindExportedFunctions find all exported functions in given directory.
func GetBlankImports ¶
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 OpenAPI3Generator ¶
OpenAPI3Generator injects openapi3 generator into given Goyave project. Returns the injected 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 ¶
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.