config

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version               = "0.10.2"
	SupportedTemplVersion = "v0.3.819"
)

Variables

This section is empty.

Functions

func PrintVersionInfoAndExit added in v0.5.0

func PrintVersionInfoAndExit()

Types

type CmdStr

type CmdStr string

func (CmdStr) Cmd added in v0.7.4

func (c CmdStr) Cmd() string

Cmd returns only the command without arguments.

func (*CmdStr) UnmarshalText

func (c *CmdStr) UnmarshalText(t []byte) error

type Config

type Config struct {
	// Compiler defines optional Go compiler flags
	Compiler *ConfigCompiler `yaml:"compiler"`

	App ConfigApp `yaml:"app"`

	// Log specifies logging related configurations.
	Log ConfigLog `yaml:"log"`

	// Debounce is the file watcher debounce duration.
	Debounce struct {
		// Templ is the browser tab reload debounce duration
		// for _templ.txt changes.
		Templ time.Duration `yaml:"templ"`

		// Go is the Go recompilation debounce duration.
		Go time.Duration `yaml:"go"`
	} `yaml:"debounce"`

	// ProxyTimeout defines for how long the proxy must try retry
	// requesting the application server when receiving connection refused error.
	ProxyTimeout time.Duration `yaml:"proxy-timeout"`

	// Lint runs golangci-lint before building if enabled.
	Lint bool `yaml:"lint"`

	// Format enables running `templ fmt` on `.templ` file changes.
	Format bool `yaml:"format"`

	// TemplierHost is the Templiér HTTP server host address.
	// Example: "127.0.0.1:9999".
	TemplierHost string `yaml:"templier-host" validate:"url,required"`

	// TLS is optional, will serve HTTP instead of HTTPS if nil.
	TLS *struct {
		Cert string `yaml:"cert" validate:"filepath,required"`
		Key  string `yaml:"key" validate:"filepath,required"`
	} `yaml:"tls"`

	// CustomWatchers defines custom file change watchers.
	CustomWatchers []ConfigCustomWatcher `yaml:"custom-watchers"`
}

func MustParse

func MustParse() *Config

func (*Config) CompilerEnv added in v0.9.0

func (c *Config) CompilerEnv() []string

func (*Config) CompilerFlags added in v0.9.0

func (c *Config) CompilerFlags() []string

type ConfigApp

type ConfigApp struct {
	// DirSrcRoot is the source root directory for the application server.
	DirSrcRoot string `yaml:"dir-src-root" validate:"dirpath,required"`

	// Exclude defines glob expressions to match files exluded from watching.
	Exclude GlobList `yaml:"exclude"`

	// DirCmd is the server cmd directory containing the `main` function.
	DirCmd string `yaml:"dir-cmd" validate:"dirpath,required"`

	// DirWork is the working directory to run the application server from.
	DirWork string `yaml:"dir-work" validate:"dirpath,required"`

	// Flags are the CLI arguments to be passed to the application server.
	Flags SpaceSeparatedList `yaml:"flags"`

	// Host is the application server host address.
	// Example: "https://local.example.com:8080"
	Host URL `yaml:"host" validate:"required"`
	// contains filtered or unexported fields
}

func (*ConfigApp) DirSrcRootAbsolute

func (c *ConfigApp) DirSrcRootAbsolute() string

type ConfigCompiler added in v0.9.0

type ConfigCompiler struct {
	// Gcflags is the -gcflags compiler flags to be passed to the go
	// compiler when compiling the application server.
	Gcflags string `yaml:"gcflags"`

	// Ldflags provides the -ldflags CLI argument to Go compiler
	// to pass on each go tool link invocation.
	Ldflags string `yaml:"ldflags"`

	// Asmflags is equivalent to `-asmflags '[pattern=]arg list'`.
	Asmflags string `yaml:"asmflags"`

	// Tags lists additional build tags to consider satisfied during the build.
	Tags []string `yaml:"tags"`

	// Race sets `-race` when true.
	Race bool `yaml:"race"`

	// Trimpath sets `-trimpath` when true.
	Trimpath bool `yaml:"trimpath"`

	// Msan sets `-msan` when true.
	Msan bool `yaml:"msan"`

	// P sets the number of programs, such as build commands that can be run in
	// parallel. The default is GOMAXPROCS, normally the number of CPUs available.
	P uint32 `yaml:"p"`

	// Env passes environment variables to the Go compiler.
	Env map[string]string `yaml:"env"`
	// contains filtered or unexported fields
}

type ConfigCustomWatcher

type ConfigCustomWatcher struct {
	// Name is the display name for the custom watcher.
	Name TrimmedString `yaml:"name"`

	// Include specifies glob expressions for what files to watch.
	Include GlobList `yaml:"include"`

	// Exclude specifies glob expressions for what files to ignore
	// that would otherwise match `include`.
	Exclude GlobList `yaml:"exclude"`

	// Cmd specifies the command to run when an included file changed.
	// Cmd will be executed in app.dir-work. This is optional and can be left empty
	// since sometimes all you want to do is rebuild & restart or just restart
	// the server, such as when a config file changes.
	Cmd CmdStr `yaml:"cmd"`

	// FailOnError specifies that in case cmd returns error code 1 the output
	// of the execution should be displayed in the browser, just like
	// for example if the Go compiler fails to compile.
	FailOnError bool `yaml:"fail-on-error"`

	// Debounce defines how long to wait for more file changes
	// after the first one occured before executing cmd.
	// Default debounce duration is applied if left empty.
	Debounce time.Duration `yaml:"debounce"`

	// Requires defines what action is required when an included file changed.
	// Accepts the following options:
	//
	//  - "" (or simply keep the field empty): no action, just execute Cmd.
	//  - "reload": Requires browser tabs to be reloaded.
	//  - "restart": Requires the server process to be restarted.
	//  - "rebuild": Requires the server to be rebuilt and restarted.
	//
	// This option overwrites regular behavior (for non-templ file changes it's "rebuild")
	Requires Requires `yaml:"requires"`
}

func (ConfigCustomWatcher) Validate

func (w ConfigCustomWatcher) Validate() error

type ConfigLog added in v0.7.0

type ConfigLog struct {
	// Level accepts either of:
	//  - "": empty string is the same as "erronly"
	//  - "erronly": error logs only.
	//  - "verbose": verbose logging of relevant events.
	//  - "debug": verbose debug logging.
	Level LogLevel `yaml:"level"`

	// ClearOn accepts either of:
	//  - "": disables console log clearing.
	//  - "restart": clears console logs only on app server restart.
	//  - "file-change": clears console logs on every file change.
	ClearOn LogClear `yaml:"clear-on"`

	// PrintJSDebugLogs enables Templiér injected javascript
	// debug logs in the browser.
	PrintJSDebugLogs bool `yaml:"print-js-debug-logs"`
}

type GlobList

type GlobList []string

func (GlobList) Validate

func (e GlobList) Validate() error

type LogClear added in v0.7.0

type LogClear int8
const (
	LogClearDisabled LogClear = iota
	LogClearOnRestart
	LogClearOnFileChange
)

func (*LogClear) UnmarshalText added in v0.7.0

func (l *LogClear) UnmarshalText(text []byte) error

type LogLevel added in v0.7.0

type LogLevel log.LogLevel

func (*LogLevel) UnmarshalText added in v0.7.0

func (l *LogLevel) UnmarshalText(text []byte) error

type Requires

type Requires action.Type

func (*Requires) UnmarshalText

func (r *Requires) UnmarshalText(text []byte) error

type SpaceSeparatedList

type SpaceSeparatedList []string

func (*SpaceSeparatedList) UnmarshalText

func (l *SpaceSeparatedList) UnmarshalText(t []byte) error

type TrimmedString added in v0.7.4

type TrimmedString string

TrimmedString removes all leading and trailing white space, as defined by Unicode, when parsing from text as TextUnmarshaler.

func (*TrimmedString) UnmarshalText added in v0.7.4

func (t *TrimmedString) UnmarshalText(text []byte) error

type URL

type URL struct{ URL *url.URL }

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(t []byte) error

Jump to

Keyboard shortcuts

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