config

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "0.7.2"

Variables

This section is empty.

Functions

func PrintVersionInfoAndExit added in v0.5.0

func PrintVersionInfoAndExit()

Types

type CmdStr

type CmdStr string

func (*CmdStr) UnmarshalText

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

type Config

type Config struct {
	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"`

	// 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"`
	// contains filtered or unexported fields
}

func MustParse

func MustParse() *Config

func (*Config) ServerOutPath

func (c *Config) ServerOutPath() 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"`

	// GoFlags are the CLI arguments to be passed to the go compiler when
	// compiling the application server.
	GoFlags SpaceSeparatedList `yaml:"go-flags"`

	// 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 ConfigCustomWatcher

type ConfigCustomWatcher struct {
	// Name is the display name for the custom watcher.
	Name string `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 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