Documentation
¶
Index ¶
- Constants
- Variables
- func CleanModule(module string) (string, error)
- type Config
- type Inspector
- type Project
- func (*Project) Domain(module string) string
- func (p *Project) ImportPath(module, pkg string) string
- func (p *Project) Inspect(configPath, source string) (*Inspector, error)
- func (p *Project) ModuleDir(module string) string
- func (p *Project) ModuleFile(module string) string
- func (*Project) ModulePackageName(module string) string
- func (p *Project) PackageDir(module, pkg string) string
- func (p *Project) PermissionToken(module, entity, action string) string
- func (p *Project) Rel(path string) string
- func (p *Project) ResourceName(module, entity string) string
- type ResourceConfig
Constants ¶
const AppConfigName = "application.toml"
AppConfigName is the runtime configuration file the framework loads and the generators read data source credentials from.
const ConfigFileName = "vef.yml"
ConfigFileName is the project-level generation config vef-cli reads from the module root. Every key has a default, so the file is optional; `new project` writes one so the conventions are visible rather than implied.
Variables ¶
var ( // ErrNotAGoModule reports that no go.mod was found in the starting directory // or any of its parents, so there is no project to generate into. ErrNotAGoModule = errors.New("no go.mod found in this directory or any parent") // ErrInvalidModule reports a business module path the generators could not // build valid Go from. ErrInvalidModule = errors.New("invalid module") )
var DefaultOps = []string{"find_page", "find_all", "find_options", "create", "update", "delete"}
DefaultOps is the operation set `new resource` generates when the project does not narrow it — the combination the framework's CRUD resources use for an ordinary master-data entity.
var ErrDataSourceMissing = errors.New("data source not declared in application.toml")
ErrDataSourceMissing reports that the requested data source is absent from the project's application.toml.
var ErrInvalidModuleRoot = errors.New("invalid module_root")
ErrInvalidModuleRoot reports a module_root that cannot form elements of a Go import path, so every import the generators emit under it would be malformed.
Functions ¶
func CleanModule ¶
CleanModule normalizes a business module path and rejects one that cannot become Go.
Every segment is a directory holding Go packages and the last one is also a package name, so each has to be a Go identifier. Without this check a stray flag value — an empty string, a trailing slash, a hyphen — is only caught when the rendered file fails to parse, which reports a syntax error inside a file the generator itself just wrote and reads as a bug in the tool.
Types ¶
type Config ¶
type Config struct {
// ModuleRoot is the directory business modules live under, relative to the
// project root.
ModuleRoot string `mapstructure:"module_root"`
// Resource holds the conventions `new resource` generates against.
Resource ResourceConfig `mapstructure:"resource"`
}
Config is vef.yml with defaults applied.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the configuration a project with no vef.yml generates under.
func LoadConfig ¶
LoadConfig reads root/vef.yml over the defaults. A missing file is not an error; a malformed one is, because silently generating against defaults the project deliberately overrode would produce code that looks right and is wrong everywhere.
type Inspector ¶
type Inspector struct {
// Service reads table metadata from the connected data source.
Service schema.Service
// Kind is the data source's dialect, which drives type mapping.
Kind config.DBKind
// contains filtered or unexported fields
}
Inspector pairs a live schema.Service with the connection behind it so the caller can release it.
type Project ¶
type Project struct {
// Root is the absolute path of the directory holding go.mod.
Root string
// ModulePath is the go.mod module path, the prefix of every import the
// generators emit.
ModulePath string
// Config holds vef.yml with defaults applied.
Config Config
}
Project is the resolved context every generator runs in: where the project lives, what its Go module is called, and the conventions it generates under.
func Locate ¶
Locate walks up from start looking for go.mod and loads the project's generation config. start may be relative; the resolved Root is absolute.
func (*Project) Domain ¶
Domain returns the module's top-level segment. Permission tokens are scoped to it rather than to the full nested path: hr/emp and hr/ctr both issue hr.<entity>.<action>.
func (*Project) ImportPath ¶
ImportPath returns the Go import path of one package inside a module.
Empty segments are dropped rather than joined: a project whose modules live at its root has no module root to name, and an import path may not carry an empty element.
func (*Project) Inspect ¶
Inspect opens the named data source (empty means primary) declared by the project's application.toml and returns a schema inspector over it.
configPath overrides the file location; when empty the project's configs/application.toml is used, matching where the framework itself looks first.
func (*Project) ModuleDir ¶
ModuleDir returns the absolute directory of a business module. The module may be nested (hr/emp), which is how the framework's own consumers group a large domain into sub-modules.
func (*Project) ModuleFile ¶
ModuleFile returns the absolute path of a module's module.go, the file both resource and service registration is appended to.
func (*Project) ModulePackageName ¶
ModulePackageName returns the Go package name of a module's own package, which is the last segment of a possibly nested module path.
func (*Project) PackageDir ¶
PackageDir returns the absolute directory of one package inside a module, for example the model or resource package.
func (*Project) PermissionToken ¶
PermissionToken renders the permission token for one operation from the configured template. An empty template means the project does not scope this resource by permission.
func (*Project) Rel ¶
Rel renders an absolute path inside the project relative to its root, for readable command output. A path outside the project is returned unchanged.
func (*Project) ResourceName ¶
ResourceName renders the API resource name for an entity from the configured template.
type ResourceConfig ¶
type ResourceConfig struct {
// Name is the api.NewRPCResource name template.
Name string `mapstructure:"name"`
// Permission is the RequiredPermission token template. Empty generates no
// permission at all, which suits a project that authorizes elsewhere.
Permission string `mapstructure:"permission"`
// Ops lists the CRUD operations a generated resource embeds.
Ops []string `mapstructure:"ops"`
// Audit enables EnableAudit on the generated mutating operations.
Audit bool `mapstructure:"audit"`
// AuditUserModel is the qualified model variable passed to
// WithAuditUserNames on read operations, written as
// <import path>.<identifier> (for example acme/internal/sys/model.UserModel).
// Empty generates no WithAuditUserNames call.
AuditUserModel string `mapstructure:"audit_user_model"`
}
ResourceConfig captures the project's API resource conventions. Name and Permission are templates over {module} (the full, possibly nested module path), {domain} (its first segment), {entity} and {action}.