shared

package
v1.8.1-0...-100120b Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryHTTP      = "HTTP:"
	CategoryTemplates = "TEMPLATES:"
	CategoryCodes     = "HTTP CODES:"
	CategoryFormats   = "FORMATS:"
	CategoryBuild     = "BUILD:"
	CategoryOther     = "OTHER:"
)

Variables

View Source
var AddHTTPCodesFlag = cli.StringMapFlag{
	Name: "add-code",
	Usage: "To add a new HTTP status code, provide the code and its message/description using this flag (the format " +
		"should be '%code%=%message%/%description%'; the code may contain a wildcard '*' to cover multiple codes at " +
		"once, for example, '4**' will cover all 4xx codes unless a more specific code is described previously)",
	Config:   cli.StringConfig{TrimSpace: true},
	Category: CategoryCodes,
	Validator: func(codes map[string]string) error {
		for code, msgAndDesc := range codes {
			if code == "" {
				return fmt.Errorf("missing HTTP code")
			} else if len(code) != 3 {
				return fmt.Errorf("wrong HTTP code [%s]: it should be 3 characters long", code)
			}

			if parts := strings.SplitN(msgAndDesc, "/", 3); len(parts) < 1 || len(parts) > 2 {
				return fmt.Errorf("wrong message/description format for HTTP code [%s]: %s", code, msgAndDesc)
			} else if parts[0] == "" {
				return fmt.Errorf("missing message for HTTP code [%s]", code)
			}
		}

		return nil
	},
}
View Source
var AddTemplatesFlag = cli.StringSliceFlag{
	Name: "add-template",
	Usage: "To add a new template, provide the path to the file using this flag (the filename without the extension " +
		"will be used as the template name)",
	Config:   cli.StringConfig{TrimSpace: true},
	Sources:  cli.EnvVars("ADD_TEMPLATE"),
	Category: CategoryTemplates,
	Validator: func(paths []string) error {
		for _, path := range paths {
			if path == "" {
				return fmt.Errorf("missing template path")
			}

			if stat, err := os.Stat(path); err != nil || stat.IsDir() {
				return fmt.Errorf("wrong template path [%s]", path)
			}
		}

		return nil
	},
}
View Source
var DisableL10nFlag = cli.BoolFlag{
	Name:     "disable-l10n",
	Usage:    "Disable localization of error pages (if the template supports localization)",
	Sources:  cli.EnvVars("DISABLE_L10N"),
	Category: CategoryOther,
	OnlyOnce: true,
}
View Source
var DisableMinificationFlag = cli.BoolFlag{
	Name:     "disable-minification",
	Usage:    "Disable the minification of HTML pages, including CSS, SVG, and JS (may be useful for debugging)",
	Sources:  cli.EnvVars("DISABLE_MINIFICATION"),
	Category: CategoryOther,
	OnlyOnce: true,
}
View Source
var DisableTemplateNamesFlag = cli.StringSliceFlag{
	Name:     "disable-template",
	Usage:    "Disable the specified template by its name (useful to disable the built-in templates and use only custom ones)",
	Config:   cli.StringConfig{TrimSpace: true},
	Category: CategoryTemplates,
}
View Source
var ListenAddrFlag = cli.StringFlag{
	Name:     "listen",
	Aliases:  []string{"l"},
	Usage:    "IP (v4 or v6) address to listen on",
	Value:    "0.0.0.0",
	Sources:  cli.EnvVars("LISTEN_ADDR"),
	Category: CategoryHTTP,
	OnlyOnce: true,
	Config:   cli.StringConfig{TrimSpace: true},
	Validator: func(ip string) error {
		if ip == "" {
			return fmt.Errorf("missing IP address")
		}

		if net.ParseIP(ip) == nil {
			return fmt.Errorf("wrong IP address [%s] for listening", ip)
		}

		return nil
	},
}
View Source
var ListenPortFlag = cli.UintFlag{
	Name:     "port",
	Aliases:  []string{"p"},
	Usage:    "TCP port number",
	Value:    8080,
	Sources:  cli.EnvVars("LISTEN_PORT"),
	Category: CategoryHTTP,
	OnlyOnce: true,
	Validator: func(port uint64) error {
		if port == 0 || port > 65535 {
			return fmt.Errorf("wrong TCP port number [%d]", port)
		}

		return nil
	},
}

Functions

func ParseHTTPCodes

func ParseHTTPCodes(codes map[string]string) map[string]config.CodeDescription

ParseHTTPCodes converts a map of HTTP status codes and their messages/descriptions into a map of codes and descriptions. Should be used together with AddHTTPCodesFlag.

Types

This section is empty.

Jump to

Keyboard shortcuts

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