Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidEnv represents that the given runtime environment is not // registered or supported. ErrInvalidEnv = errors.New("environment: invalid env") // ErrLocked indicates that the current runtime environment is locked // and cannot be changed. ErrLocked = errors.New("environment: locked") )
Functions ¶
func In ¶
In returns whether the current runtime environment is in the given runtime environment list.
func Is ¶
Is returns whether the given runtime environment is equal to the current runtime environment.
func Listen ¶
func Listen(listener Listener)
Listen adds a given runtime environment listener. If the given listener is nil, ignore it.
func Lock ¶
func Lock()
Lock locks the current runtime environment. After locking, the current runtime environment cannot be changed.
func Register ¶
func Register(env Env)
Register registers a custom runtime environment. If you want to add a custom environment, this method must be called before the Set() method.
func Registered ¶
Registered determines whether the given runtime environment is already registered.
func Set ¶
Set sets the current runtime environment. If the given runtime environment is not supported, ErrInvalidEnv error is returned. If the current runtime environment is locked, ErrLocked error is returned.
func SetAndLock ¶
SetAndLock sets and locks the current runtime environment. If the runtime environment settings fail, they are not locked.
Types ¶
type Env ¶
type Env string
Env type defines the runtime environment.
const ( // Development is the development environment, which is also the default // runtime environment. Development Env = "development" // Alpha is a alpha environment, usually used for initial quality acceptance. Alpha Env = "alpha" // Testing is a test environment, usually used for initial quality acceptance. Testing Env = "testing" // Prerelease is a pre release environment, usually used for grayscale // testing or quality acceptance. Prerelease Env = "prerelease" // Production is the production environment and the final deployment // environment of the application. Production Env = "production" )
func (Env) In ¶
In method returns whether the current runtime environment is in the given runtime environment list.
type Listener ¶
type Listener func(after, before Env)
Listener defines the runtime environment listener. Listeners are used to receive notifications when the runtime environment changes.
func UnListen ¶
func UnListen() Listener
UnListen removes and returns to the recently added listener. If there is no listener to be removed, nil is returned.
func UnListenAll ¶
func UnListenAll() []Listener
UnListenAll removes and returns all added listeners. If there is no listener to be removed, nil is returned.
type Manager ¶
type Manager interface { // Get method returns the current runtime environment. Get() Env // Is returns whether the given runtime environment is equal to the // current runtime environment. Is(Env) bool // In returns whether the current runtime environment is in the given // runtime environment list. In(envs []Env) bool // Register method registers a custom runtime environment. // If you want to add a custom environment, this method must be called // before the Manager.Set() method. Register(Env) // Registered determines whether the given runtime environment is already registered. Registered(Env) bool // Lock method locks the current runtime environment. // After locking, the current runtime environment cannot be changed. Lock() // Locked method returns whether the current runtime environment is locked. Locked() bool // Set method sets the current runtime environment. // If the given runtime environment is not supported, ErrInvalidEnv error is returned. // If the current runtime environment is locked, ErrLocked error is returned. Set(Env) error // SetAndLock method sets and locks the current runtime environment. // If the runtime environment settings fail, they are not locked. SetAndLock(Env) error // Listen method adds a given runtime environment listener. // If the given listener is nil, ignore it. Listen(Listener) // UnListen removes and returns to the recently added listener. // If there is no listener to be removed, nil is returned. UnListen() Listener // UnListenAll removes and returns all added listeners. // If there is no listener to be removed, nil is returned. UnListenAll() []Listener }
Manager interface type defines a runtime environment manager. An independent system should share an independent manager instance.