Documentation
¶
Overview ¶
Package gen generates project files from platformgo.yaml.
It produces the module wiring, their settings and the environment example. This is what removes manual edits when modules are added or removed: only the domain part stays in project code.
Index ¶
- Constants
- func Apply(dir string, files map[string][]byte) ([]string, error)
- func Changed(dir string, files map[string][]byte) ([]string, error)
- func DomainDir(f *spec.File) string
- func EnumsCode(f *spec.File, project fs.FS) ([]byte, error)
- func Files(dir string, f *spec.File) (map[string][]byte, error)
- func FilesFrom(f *spec.File, project fs.FS) (map[string][]byte, error)
- func IsGenerated(content []byte) bool
- func MonitoringFiles(f *spec.File, project fs.FS) (map[string][]byte, error)
- func NewMigration(dir, name string, now time.Time) (string, error)
- func SettingsCode(raw []byte) ([]byte, error)
- func SettingsEnabled(f *spec.File) bool
- func SettingsSchemaPath(f *spec.File) string
- func Wiring(f *spec.File) (map[string][]byte, error)
Constants ¶
const ( BufPath = "buf.yaml" BufGenPath = "buf.gen.yaml" OpenAPIPath = "api/openapi/openapi.gen.go" // APIGenDir is where the Go code of the proto files is generated. APIGenDir = "internal/api/gen" )
Files of the api module.
const ( MessagesPath = "i18n/messages.yaml" MessagesGoPath = "i18n/messages.gen.go" I18nProtoPath = "proto/platform/i18n/v1/i18n.proto" )
Files of the i18n module.
const ( MonitoringPath = "monitoring.yml" // thresholds, owned by the project MonitoringStack = monitoringDir + "docker-compose.yml" )
Files of the monitoring module.
const ( ConfigPath = "cmd/app/config.gen.go" ModulesPath = "cmd/app/modules.gen.go" EnvPath = ".env.example" ComposePath = "docker-compose.yml" // PolicyPath is the access policy of the project; PolicyGoPath embeds it. PolicyPath = "rbac/policy.csv" PolicyGoPath = "rbac/policy.gen.go" // MigrationsPath embeds the SQL migrations of the project next to them. MigrationsPath = "db/migrations/migrations.gen.go" )
Paths of generated files, relative to the project root.
const DefaultDomainDir = "internal/domain"
DefaultDomainDir is where enums are declared unless the enums module says otherwise.
const EnumsPath = "internal/enums/enums.gen.go"
EnumsPath is the generated catalog of the enums of the project.
const I18nProto = `` /* 1541-byte string literal not displayed */
I18nProto is the field option of the platform, the same file kit/i18nx is generated from. A test keeps the two identical.
const MessagesExample = `` /* 706-byte string literal not displayed */
MessagesExample is the file a project starts from when it enables the i18n module.
const MigrationsDir = "db/migrations"
MigrationsDir is where the SQL migrations of a project live.
const MonitoringExample = `` /* 731-byte string literal not displayed */
MonitoringExample is the thresholds file a project starts from. Its sections and keys are taply's, so the numbers read the same in every project.
const PolicyExample = `` /* 380-byte string literal not displayed */
PolicyExample is the policy a project starts from when it enables the rbac module.
const SettingsExample = `` /* 354-byte string literal not displayed */
SettingsExample is the schema a project starts from when it enables the settings module: an empty schema would leave an accessor with nothing to return.
const SettingsModule = "settings"
SettingsModule is the module name whose schema drives the generation.
const SettingsPath = "internal/settings/settings.gen.go"
SettingsPath is the generated typed access to the business settings. It lives in the project so that domain code reads a setting as a method call rather than a string key.
const SqlcPath = "db/sqlc.yaml"
SqlcPath is the sqlc configuration of the project. It is generated, so the paths and type mapping stay the same in every project.
Variables ¶
This section is empty.
Functions ¶
func Apply ¶
Apply writes the generated files that differ from what the project has and returns their paths. Untouched files keep their modification time, so a build that runs generation first does not rebuild everything.
func Changed ¶
Changed returns the paths whose content in the project differs from the generated one. An empty list means generation is up to date.
func EnumsCode ¶ added in v0.3.0
EnumsCode scans the domain package of the project for go-enum markers and generates the catalog, ported from taply's enumsgen.
func Files ¶
Files returns everything platformgo generates for the project: the module wiring and, when the settings module is enabled, the typed access to the business settings.
The schema is read from the project directory, so the generated code always matches the file a developer just edited.
func FilesFrom ¶ added in v0.2.0
FilesFrom is Files with the project read through project. apply passes the disk with the files it is about to create laid over it.
func IsGenerated ¶ added in v0.2.0
IsGenerated reports whether content carries the mark platformgo puts on the files it generates. A generated file that lost the mark has been taken over by hand, and apply leaves it alone.
func MonitoringFiles ¶ added in v0.3.0
MonitoringFiles generates the monitoring stack of the project: an OpenTelemetry collector next to the service and Prometheus, Alertmanager, Loki, Tempo and Grafana, with the dashboard and the alerts of the enabled modules.
func NewMigration ¶ added in v0.2.0
NewMigration creates an empty goose migration named after the time and the given name and returns its path relative to the project. The timestamp keeps files ordered and avoids number clashes between branches.
func SettingsCode ¶
SettingsCode generates the typed access from the schema file contents.
func SettingsEnabled ¶
SettingsEnabled reports whether the project enables the settings module.
func SettingsSchemaPath ¶
SettingsSchemaPath is the schema file of the project: settings.yaml unless the module section names another one.
Types ¶
This section is empty.