generator

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(
	dstDir string, pkgName string, m *model.App, perm os.FileMode, opts Options,
) error

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) Byte

func (w *Writer) Byte(b byte)

Byte appends a single byte to the buffer.

func (*Writer) Line

func (w *Writer) Line(indent int, s string)

Line writes an indented line. indent is the number of leading tabs.

func (*Writer) Linef

func (w *Writer) Linef(indent int, format string, args ...any)

Linef writes an indented formatted line. indent is the number of leading tabs.

func (*Writer) Raw

func (w *Writer) Raw(s string)

Raw appends a string to the buffer.

func (*Writer) Rawf

func (w *Writer) Rawf(format string, args ...any)

Rawf appends a formatted string to the buffer.

func (*Writer) Reset

func (w *Writer) Reset()

func (*Writer) WriteApp

func (w *Writer) WriteApp(pkgName string, m *model.App)

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

func (w *Writer) WritePkgAction(m *model.App)

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

func (w *Writer) WritePkgHref(m *model.App)

WritePkgHref generates code for the datapagesgen/href package and appends it to buffer.

Directories

Path Synopsis
Package skeleton provides templates for initializing a new Datapages project.
Package skeleton provides templates for initializing a new Datapages project.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL