app

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

xtemplate cmd

The cmd package is xtemplate's Command Line Interface (CLI) application.

If you want to customize the xtemplate build with a specific database driver, custom template funcs, or to have more control over application startup copy main.go to a new package and provide override funcs to call to xtemplate.Main().

Build
# build from ./cmd
go build -o xtemplate

# build from repo root
go build -o xtemplate ./cmd

# build with sqlite3 driver and json extensions
GOFLAGS='-tags="sqlite_json"' CGO_ENABLED=1 go build -o xtemplate ./cmd
Usage
$ ./xtemplate -help
xtemplate is a hypertext preprocessor and html templating http server

Usage: ./xtemplate [options]

Options:
  -listen string              Listen address (default "0.0.0.0:8080")

  -template-path string       Directory where templates are loaded from (default "templates")
  -watch-template bool        Watch the template directory and reload if changed (default true)
  -template-extension string  File extension to look for to identify templates (default ".html")
  -minify bool                Preprocess the template files to minimize their size at load time (default false)
  -ldelim string              Left template delimiter (default "{{")
  -rdelim string              Right template delimiter (default "}}")

  -context-path string        Directory that template definitions are given direct access to. No access is given if empty (default "")
  -watch-context bool         Watch the context directory and reload if changed (default false)

  -db-driver string           Name of the database driver registered as a Go 'sql.Driver'. Not available if empty. (default "")
  -db-connstr string          Database connection string

  -c string                   Config values, in the form 'x=y'. Can be used multiple times

  -log int                    Log level. Log statements below this value are omitted from log output, DEBUG=-4, INFO=0, WARN=4, ERROR=8 (Default: 0)
  -help                       Display help

Examples:
    Listen on port 80:
    $ ./xtemplate -listen :80

    Specify a context directory and reload when it changes:
    $ ./xtemplate -context-path context/ -watch-context

    Parse template files matching a custom extension and minify them:
    $ ./xtemplate -template-extension ".go.html" -minify

    Open the specified db and makes it available to template files as '.DB':
    $ ./xtemplate -db-driver sqlite3 -db-connstr 'file:rss.sqlite?_journal=WAL'

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 configs to override the defaults like:

app.Main(xtemplate.WithFooConfig())

Types

type Args

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

func (Args) Version

func (Args) Version() string

Jump to

Keyboard shortcuts

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