appname

package
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package appname provides containers for named applications.

Application name foo-bar translate to environment variable prefix FOO_BAR_.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen(ctx context.Context, container Container, defaultPort uint16) (net.Listener, error)

Listen listens on the container's port, falling back to defaultPort.

func ReadConfig

func ReadConfig(container Container, value interface{}) error

ReadConfig reads the configuration from the YAML configuration file config.yaml in the configuration directory.

If the file does not exist, this is a no-op. The value should be a pointer to unmarshal into.

func ReadSecret

func ReadSecret(container Container, name string) (string, error)

ReadSecret returns the contents of the file at path filepath.Join(container.ConfigDirPath(), secretRelDirPath, name).

func WriteConfig

func WriteConfig(container Container, value interface{}) error

WriteConfig writes the configuration to the YAML configuration file config.yaml in the configuration directory.

The directory is created if it does not exist. The value should be a pointer to marshal.

Types

type Container

type Container interface {
	// AppName is the application name.
	//
	// The name must be in [a-zA-Z0-9-_].
	AppName() string
	// ConfigDirPath is the config directory path for the named application.
	//
	// First checks for $APP_NAME_CONFIG_DIR.
	// If this is not set, uses app.ConfigDirPath()/app-name.
	// Unnormalized.
	ConfigDirPath() string
	// CacheDirPath is the cache directory path for the named application.
	//
	// First checks for $APP_NAME_CACHE_DIR.
	// If this is not set, uses app.CacheDirPath()/app-name.
	// Unnormalized.
	CacheDirPath() string
	// DataDirPath is the data directory path for the named application.
	//
	// First checks for $APP_NAME_DATA_DIR.
	// If this is not set, uses app.DataDirPath()/app-name.
	// Unnormalized.
	DataDirPath() string
	// Port is the port to use for serving.
	//
	// First checks for $APP_NAME_PORT.
	// If this is not set, checks for $PORT.
	// If this is not set, returns 0, which means no port is known.
	// Returns error on parse.
	Port() (uint16, error)
}

Container is a container.

func NewContainer

func NewContainer(envContainer app.EnvContainer, name string) (Container, error)

NewContainer returns a new Container.

The name must be in [a-zA-Z0-9-_].

Jump to

Keyboard shortcuts

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