app

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

xtemplate app

CLI application layer: parse flags and JSON, construct an xtemplate.Server, and serve. The core library stays free of CLI concerns.

One package (app) and one main (cmd/xtemplate) cover all built-in template controllers via --controller-type / JSON "controller":

Controller type Package Role
os core Serve from a local directory; no reload. Core DefaultControllerType.
watchfs controllers/watchfs Reload when the template root (and --watch dirs) change.
git controllers/git Load/reload templates from a Git remote

cmd/xtemplate blank-imports providers, drivers, and optional controllers, sets DefaultControllerType to watchfs, then calls app.Main — so the release binary defaults to live reload.

Customize a binary

Copy cmd/xtemplate into your own module when you need different drivers, FuncMaps, providers, or defaults. Pass xtemplate.Options into Main:

package main

import (
	"github.com/infogulch/xtemplate"
	"github.com/infogulch/xtemplate/app"

	_ "github.com/infogulch/xtemplate/providers/dotsql"
	_ "github.com/infogulch/xtemplate/controllers/watchfs"
	_ "github.com/jackc/pgx/v5/stdlib" // driver name "pgx"
)

func main() {
	xtemplate.DefaultControllerType = "watchfs"
	app.Main(
		// xtemplate.WithProvider(func() xtemplate.Provider { return myProvider{} }),
		// xtemplate.WithFuncMaps(...),
	)
}

Docs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(overrides ...xtemplate.Option)

Main can be called from your func main() if you want your program to act like the default xtemplate cli, or use it as a reference for making your own. Provide config options to override the defaults like:

app.Main(xtemplate.WithFooConfig())

func Serve added in v0.9.0

func Serve(config *Config, options ...xtemplate.Option)

Serve sets up the xtemplate server from config and serves it. Serve blocks until the server stops.

Types

type Config added in v0.9.0

type Config struct {
	xtemplate.Config
	Listen      string   `json:"listen" arg:"-l,--listen"`
	LogLevel    int      `json:"log_level" arg:"--loglevel" default:"-2"`
	Configs     []string `json:"-" arg:"-c,--config,separate"`
	ConfigFiles []string `json:"-" arg:"-f,--config-file,separate"`
}

Config is the CLI app configuration: listen address, log level, and embedded xtemplate.Config for template/server options.

func LoadConfig added in v0.9.0

func LoadConfig(args []string) (*Config, error)

LoadConfig merges configuration: CLI flags > inline JSON > files > defaults. Pipeline: defaults → pass0 bootstrap → merge JSON → materialize controller (CLI type > JSON > default) → parse CLI (help/version exit via go-arg) → finalize. Pass nil for os.Args[1:].

func (Config) Epilogue added in v0.9.0

func (Config) Epilogue() string

Epilogue is shown at the end of --help.

func (*Config) SetDefaults added in v0.9.0

func (a *Config) SetDefaults()

SetDefaults sets the default values for this Config.

func (*Config) UnmarshalJSON added in v0.11.0

func (a *Config) UnmarshalJSON(data []byte) error

UnmarshalJSON fills app + embedded xtemplate fields. Uses a method-less Config alias so listen/log_level are not dropped. listen and log_level overwrite only when present so defaults survive omitted keys. Call CheckLegacyTemplateKeys before this when needed (LoadConfig does).

func (Config) Version added in v0.9.0

func (Config) Version() string

Jump to

Keyboard shortcuts

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