Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edoger/zkits-environment
A concise global application runtime environment manager.
https://github.com/edoger/zkits-environment
environment go golang runtime zkits
Last synced: 11 days ago
JSON representation
A concise global application runtime environment manager.
- Host: GitHub
- URL: https://github.com/edoger/zkits-environment
- Owner: edoger
- License: apache-2.0
- Created: 2020-03-31T14:21:59.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-11T04:33:58.000Z (over 3 years ago)
- Last Synced: 2024-06-20T14:27:04.961Z (7 months ago)
- Topics: environment, go, golang, runtime, zkits
- Language: Go
- Homepage:
- Size: 60.5 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ZKits Environment Library #
[![ZKits](https://img.shields.io/badge/ZKits-Library-f3c)](https://github.com/edoger/zkits-environment)
[![Build Status](https://travis-ci.org/edoger/zkits-environment.svg?branch=master)](https://travis-ci.org/edoger/zkits-environment)
[![Build status](https://ci.appveyor.com/api/projects/status/8a6g4bthvvdpa2oo/branch/master?svg=true)](https://ci.appveyor.com/project/edoger56924/zkits-environment/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/edoger/zkits-environment/badge.svg?branch=master)](https://coveralls.io/github/edoger/zkits-environment?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5b5f1e62d67846b3813fc77634b8dff3)](https://www.codacy.com/manual/edoger/zkits-environment?utm_source=github.com&utm_medium=referral&utm_content=edoger/zkits-environment&utm_campaign=Badge_Grade)
[![Go Report Card](https://goreportcard.com/badge/github.com/edoger/zkits-environment)](https://goreportcard.com/report/github.com/edoger/zkits-environment)
[![Golang Version](https://img.shields.io/badge/golang-1.14+-orange)](https://github.com/edoger/zkits-environment)## About ##
This package is a library of ZKits project.
This library provides the function of managing the runtime environment for the application.
Generally, no additional work is needed to realize the type of runtime environment shared
between the various components of the application.## Why? ##
Each component in an application usually needs to have different behaviors (such as more detailed log output)
in different runtime environments.
However, it is quite tedious for each component to maintain a set of runtime environment.
In some large-scale applications, it is impossible to do so.
This library is to solve this problem.
Let's manage the runtime environment more conveniently within the application.## Install ##
```sh
go get -u -v github.com/edoger/zkits-environment
```## Usage ##
```go
package main
import (
"github.com/edoger/zkits-environment"
)func main() {
// Get the current runtime environment.
environment.Get()// Set the runtime environment value.
// If the given runtime environment is not supported, ErrInvalidEnv error is returned.
// If the current runtime environment is locked, ErrLocked error is returned.
// environment.Development // "development"
// environment.Testing // "testing"
// environment.Prerelease // "prerelease"
// environment.Production // "production"
environment.Set(environment.Testing)// Register functions can register any custom runtime environment.
// Note: The Register method must be invoked before calling the Set method.
environment.Register("foo")
environment.Registered("foo") // true// Lock locks the current runtime environment.
// After locking, the current runtime environment cannot be changed.
environment.Lock()
// SetAndLock sets and locks the current runtime environment.
// If the runtime environment settings fail, they are not locked.
environment.SetAndLock(environment.Testing)// Listen adds a given runtime environment listener.
// When the runtime environment changes, all registered listeners will be executed.
environment.Listen(func(after, before environment.Env) {
// Do something!
})// New creates and returns a new instance of the runtime environment manager.
// The default runtime environment is Development, and all built-in runtime environments
// have been registered.
// The runtime environment manager has all the functions and methods of the same name!
manager := environment.New()// NewEmpty creates and returns an empty instance of the runtime environment manager.
// The manager returned by this function does not register any runtime environment,
// and the current runtime environment is empty.
empty := environment.NewEmpty()
}
```## License ##
[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)