Documentation
¶
Overview ¶
Package environment implements helpers to handle environment varialbes and other function for startup.
Index ¶
- Variables
- func InterruptContext() (context.Context, context.CancelFunc)
- func ParseDuration(s string) (time.Duration, error)
- func ReadSecret(lookup Environmenter, pathVariable Variable) (string, error)
- func ReadSecretWithDefault(lookup Environmenter, pathVariable Variable, defaultValue string) (string, error)
- type Environmenter
- type ForDocu
- type ForProduction
- type ForTests
- type Variable
Constants ¶
This section is empty.
Variables ¶
var (
EnvDevelopment = NewVariable("OPENSLIDES_DEVELOPMENT", "false", "If set, the service uses the default secrets.")
)
Environment variables used to configure the environment.
Functions ¶
func InterruptContext ¶
func InterruptContext() (context.Context, context.CancelFunc)
InterruptContext works like signal.NotifyContext. It returns a context that is canceled, when a signal is received.
It listens on os.Interrupt and unix.SIGTERM. If the signal is received two times, os.Exit(2) is called.
func ParseDuration ¶
ParseDuration is like time.ParseDuration but uses second as default unit.
func ReadSecret ¶
func ReadSecret(lookup Environmenter, pathVariable Variable) (string, error)
ReadSecret reads a secret from a file given by an environment variable.
If OPENSLIDES_DEVELOPMENT is set, then this will always return the string 'openslides'
func ReadSecretWithDefault ¶
func ReadSecretWithDefault(lookup Environmenter, pathVariable Variable, defaultValue string) (string, error)
ReadSecretWithDefault is like ReadSecret, but it allows to set another default value then "openslides".
Types ¶
type Environmenter ¶
Environmenter is an type, that can return the value for environment variables.
It also saves the used environment variables.
type ForDocu ¶
type ForDocu struct {
// contains filtered or unexported fields
}
ForDocu is an environment to gether the used environment variables.
It does not access the real environment varialbes but returns an empty string so that the default value is used.
func (*ForDocu) Getenv ¶
Getenv returns an empty string.
But activates development mode to use the default values for secrets.
func (*ForDocu) UseVariable ¶
UseVariable saves the used Variables
type ForProduction ¶
type ForProduction struct{}
ForProduction is an environment used for production.
It fetches the environment variables from os.Getenv().
func (*ForProduction) Getenv ¶
func (e *ForProduction) Getenv(key string) string
Getenv calls os.Getenv.
func (*ForProduction) UseVariable ¶
func (e *ForProduction) UseVariable(v Variable)
UseVariable saves the used Variables
type ForTests ¶
ForTests is a map that simulates environment variables.
func (ForTests) UseVariable ¶
UseVariable does nothing for tests.
type Variable ¶
Variable represents a environment variable. It can be used by the packages for configuration.
It is only allowed to use an environment variable at startup time.
func NewVariable ¶
NewVariable initializes a environment.Variable
func (Variable) Value ¶
func (v Variable) Value(lookup Environmenter) string
Value returns the value for an environment.Variable using a Getenver.