Documentation
¶
Overview ¶
Package ggconfig loads the project-level gst configuration file (gst.yaml) that gg commands consume at build time. It is unrelated to the runtime configuration managed by the config package.
Index ¶
Constants ¶
const FileName = "gst.yaml"
FileName is the name of the project-level gst configuration file, located next to go.mod in a business project.
Variables ¶
This section is empty.
Functions ¶
func IsLegacyPruneSettings ¶
IsLegacyPruneSettings reports whether name, as UnreadFiles returns it, is one of the prune settings files legacyPruneSettingsFiles lists: ".gg.yaml" is, "gst.yml" is not.
func NormalizeRoutePath ¶
NormalizeRoutePath splits a route path into the segments of the path it is served at, apiaction.APIPath of it, a "{name}" parameter segment converted to the ":name" form, so a rule written with or without the prefix and the generated path, which carries it, split alike: "/api/iam/admin/users/{id}/" and "iam/admin/users/{id}" both give [api iam admin users :id]. The root of the prefix, "/api" and "" alike, names no route and gives nil.
func UnreadFiles ¶
UnreadFiles returns the files in dir that look like gg configuration but that gg does not read, for the command to warn about: a project holding .gg.yaml and gst.yml next to gst.yaml gets [".gg.yaml", "gst.yml"].
Types ¶
type Config ¶
type Config struct {
// Gen configures gg gen behavior.
Gen GenConfig `yaml:"gen"`
// Prune configures gg prune, and gg gen --prune, which prunes the same
// way.
Prune PruneConfig `yaml:"prune"`
}
Config is the project-level gst configuration.
type GenConfig ¶
type GenConfig struct {
// Routes configures route generation behavior.
Routes GenRoutesConfig `yaml:"routes"`
// Models configures model registration generation behavior.
Models GenModelsConfig `yaml:"models"`
}
GenConfig configures gg gen behavior.
type GenModelsConfig ¶
type GenModelsConfig struct {
// Ignore lists models excluded from the generated model.Register calls.
// A matched model keeps its routes, services, and generated files; only
// its registration (and with it table creation) disappears.
Ignore ModelIgnoreRules `yaml:"ignore"`
}
GenModelsConfig configures model registration generation behavior.
type GenRoutesConfig ¶
type GenRoutesConfig struct {
// Ignore maps route paths to the HTTP methods excluded from code
// generation. A matched action drops out of the generated registration
// files while its service file stays on disk.
Ignore RouteIgnoreRules `yaml:"ignore"`
}
GenRoutesConfig configures route generation behavior.
type ModelIgnoreRules ¶
type ModelIgnoreRules []ModelRule
ModelIgnoreRules is the parsed gen.models.ignore mapping, one ModelRule per model name entry.
func (*ModelIgnoreRules) UnmarshalYAML ¶
func (r *ModelIgnoreRules) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML parses the model-name mapping form of gen.models.ignore:
ignore:
Profile:
from: model/iam
Widget:
Each key is the Go struct name of a model whose generated model.Register call gg gen must skip. The optional object value adds "from", restricting the rule to models declared under that directory so a project's own model of the same name elsewhere keeps registering.
type ModelRule ¶
type ModelRule struct {
// Name is the Go struct name of the model, e.g. "Profile".
Name string
// From restricts the rule to models whose file path lives under this
// directory prefix (e.g. "model/iam"). Empty means the rule applies to
// every model with a matching name. It protects a project's own model
// of the same name declared elsewhere.
From string
// Raw preserves the original entry for error and log output.
Raw string
}
ModelRule is a single parsed model registration ignore entry.
func (ModelRule) MatchesSource ¶
MatchesSource reports whether the rule applies to a model declared in the given model file. Rules without a From prefix apply to every model.
type PruneConfig ¶
type PruneConfig struct {
// Ignore lists the paths gg prune never deletes, whatever the reason it
// would: a disabled action's service file, a file in an orphan service
// directory, a directory left empty, the middleware or interceptor of a
// removed copied module, or a protobuf definition gg gen would not write
// now. Of the ignore rules it is the only one that keeps a path from gg
// prune: the project's Git ignore rules and the go command's ignores
// protect nothing, and only decide, as they do for gg check and gg gen,
// which code counts as still using a service directory. Each entry is a
// path under service/, middleware/, interceptor/ or pb/, relative to the
// project root, and matches by directory level, the way the from field of
// an ignore rule does: "service/iam" covers service/iam and everything
// below it but not service/iamx, and "service/record/list.go" covers that
// one file. Under pb/ an entry keeps the definitions alone: the Go files
// there are derived from the models and rewritten by every gg gen, so
// "pb/legacy" leaves them to be deleted and an entry naming one is
// rejected. Entries are plain paths: no wildcards, no regular expressions.
Ignore []string `yaml:"ignore"`
}
PruneConfig configures gg prune.
func (PruneConfig) Ignores ¶
func (c PruneConfig) Ignores(path string) bool
Ignores reports whether path is an Ignore entry or lies below one. With the entry "service/iam", "service/iam" and "service/iam/user/list.go" are ignored, while "service/iamx/list.go" is not.
type RouteIgnoreRules ¶
type RouteIgnoreRules []RouteRule
RouteIgnoreRules is the parsed gen.routes.ignore mapping, flattened into one RouteRule per (method, path) pair.
func (*RouteIgnoreRules) UnmarshalYAML ¶
func (r *RouteIgnoreRules) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML parses the path-to-methods mapping form of gen.routes.ignore:
ignore:
/api/signup: [POST]
/api/iam/admin/users/:id: [GET, DELETE]
/api/iam/admin/users:
methods: [GET]
from: model/iam
The path is written once and every listed method becomes one RouteRule. The object form adds "from", restricting the rule to models declared under that directory so a project can re-declare the same route elsewhere. Path keys are deduplicated with parameter names collapsed, so the same route split across several keys is rejected instead of silently merged.
type RouteRule ¶
type RouteRule struct {
// Method is the upper-cased HTTP method.
Method string
// Segments is the normalized route path split into segments. Parameter
// segments keep their ":name" form but match positionally by shape.
Segments []string
// Raw preserves the original entry for error and log output.
Raw string
// From restricts the rule to actions declared by models whose file path
// lives under this directory prefix (e.g. "model/iam"). Empty means the
// rule applies to every model declaring a matching route. It lets a
// project ignore a framework module's route while re-declaring the same
// route in its own model directory.
From string
}
RouteRule is a single parsed (method, path) ignore entry.
func ParseRouteRule ¶
ParseRouteRule parses a "METHOD /api/path" entry into a RouteRule: "get /api/iam/admin/users/{id}" gives the method GET and the segments [api iam admin users :id], and keeps the entry itself as Raw.
func (RouteRule) Match ¶
Match reports whether the rule matches the given HTTP method and route path. The route path is normalized the same way as the rule path, and parameter segments (":name" or "{name}") match positionally regardless of the parameter name.
func (RouteRule) MatchesSource ¶
MatchesSource reports whether the rule applies to an action declared in the given model file. Rules without a From prefix apply to every model.