Documentation
¶
Index ¶
- func Generate(dstDir string, pkgName string, m *model.App, perm os.FileMode, opts Options) error
- func GenerateCmd(dstDir string, appImportPath, genImportPath, genPkgName string, ...) error
- type Options
- type Writer
- func (w *Writer) Byte(b byte)
- func (w *Writer) Line(indent int, s string)
- func (w *Writer) Linef(indent int, format string, args ...any)
- func (w *Writer) Raw(s string)
- func (w *Writer) Rawf(format string, args ...any)
- func (w *Writer) Reset()
- func (w *Writer) WriteApp(pkgName string, m *model.App)
- func (w *Writer) WritePkgAction(m *model.App)
- func (w *Writer) WritePkgAssets()
- func (w *Writer) WritePkgCSRFCtx()
- func (w *Writer) WritePkgHTTPErr()
- func (w *Writer) WritePkgHref(m *model.App)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate generates the complete generated Datapages package with subpackages to destination directory dstDir. pkgName is the Go package name for the generated root package (e.g. "datapagesgen"). When m is nil, minimal stub files containing only the package declaration are written so that IDEs can resolve the import.
func GenerateCmd ¶
func GenerateCmd( dstDir string, appImportPath, genImportPath, genPkgName string, prometheus, hasSession bool, perm os.FileMode, ) error
GenerateCmd generates a default cmd/server main.go at dstDir. appImportPath and genImportPath are the full Go import paths of the app and generated packages. genPkgName is the Go package name of the generated package (e.g. "datapagesgen").
Types ¶
type Options ¶
type Options struct {
// Prometheus enables generation of Prometheus metrics instrumentation.
Prometheus bool
// AssetsURLPrefix is the URL path prefix for serving static asset files.
// When non-empty, the generator emits an assets subpackage with a URLPrefix
// constant and enables WithAssets. When empty, asset serving is disabled.
AssetsURLPrefix string
// AssetsDir is the subdirectory within the app package containing static files
// (e.g. "static"). Used as the embed.FS subdirectory and for dev-mode disk serving.
AssetsDir string
// AppDir is the path to the app source package relative to the module root
// (e.g. "app"). Used to compute the dev-mode disk path for assets.
AppDir string
// GenImport is the full import path of the generated root package
// (e.g. "github.com/example/myapp/datapagesgen").
// Required for generating subpackage imports.
GenImport string
// Version is the datapages version to stamp into the generated file headers,
// e.g. "v0.1.2". When empty, no version is included in the header.
Version string
}
Options configures code generation.
type Writer ¶
type Writer struct {
Buf []byte
// contains filtered or unexported fields
}
func (*Writer) Linef ¶
Linef writes an indented formatted line. indent is the number of leading tabs.
func (*Writer) WriteApp ¶
WriteApp generates code for the generated root package and appends it to buffer. pkgName is the Go package name (e.g. "datapagesgen").
func (*Writer) WritePkgAction ¶
WritePkgAction generates code for the datapagesgen/action package and appends it to buffer.
func (*Writer) WritePkgAssets ¶
func (w *Writer) WritePkgAssets()
WritePkgAssets generates code for the assets subpackage (assets/assets_gen.go). It emits the URLPrefix, Dir, and DevDir constants.
func (*Writer) WritePkgCSRFCtx ¶ added in v0.11.0
func (w *Writer) WritePkgCSRFCtx()
WritePkgCSRFCtx generates code for the csrfctx subpackage (csrfctx/csrfctx_gen.go). It provides an exported context key and helper functions so that templates in internal/view can read the CSRF token without importing the generated root package (which would cause a circular import).
func (*Writer) WritePkgHTTPErr ¶
func (w *Writer) WritePkgHTTPErr()
WritePkgHTTPErr generates code for the httperr subpackage (httperr/httperr_gen.go). It provides sentinel errors that action handlers can return to control the HTTP status code returned to the client.
func (*Writer) WritePkgHref ¶
WritePkgHref generates code for the datapagesgen/href package and appends it to buffer.