octolab / config Goto Github PK
View Code? Open in Web Editor NEW๐ Configuration toolkit.
Home Page: https://go.octolab.org/toolkit/config
License: MIT License
๐ Configuration toolkit.
Home Page: https://go.octolab.org/toolkit/config
License: MIT License
Motivation: there is no way to operate features (enable/disable them externally).
Draft
header := "X-Features: feature-a=true, feature-b=false"
features.Unmarshal(header)
PoC
vals := req.Header.Get(header.Features)
features.Apply(header)
if features.FindByName().Enabled {
// do something
}
Related to octolab/protocol/issues/10.
To do:
;
the separator?Motivation: extend flag types.
Draft
type Regexp regexp.Regexp
func (reg *Regexp) Decode(value string) error {
raw, err := regexp.Compile(fmt.Sprintf(`^%s$`, value))
if err != nil {
return err
}
*reg = Regexp(*raw)
return nil
}
func (reg *Regexp) Matcher() *regexp.Regexp {
return (*regexp.Regexp)(reg)
}
See https://github.com/kelseyhightower/envconfig#custom-decoders.
Motivation: there is no generic way to work with "prefixed" embedded structures. It leads to code duplication and makes it dirty.
Scope:
improve Load functionality, make it generic
https://github.com/octomation/maintainer/blob/b2543194067c4e0b4daebd0b7def287762e5f4b7/internal/config/tool.go#L25-L50
remove workaround with prefixes
solve tech debt with keys warming
https://github.com/octomation/maintainer/blob/b2543194067c4e0b4daebd0b7def287762e5f4b7/internal/config/tool_test.go#L42-L50
find a way how to make squash with prefix
work
https://github.com/octomation/maintainer/blob/b2543194067c4e0b4daebd0b7def287762e5f4b7/internal/config/tool_test.go#L82-L120
Motivation: extend flag types.
Interface
type Value interface {
String() string
Set(string) error
Type() string
}
See #4.
Motivation: there is no way to define this type of value.
Example
PoC
set := command.PersistentFlags()
set.Secret("token", "", "personal access token")
๐งฐ toolkit/config -> ๐ config
Motivation: extend flag types.
Interface
type Value interface {
String() string
Set(string) error
Type() string
}
See #4.
Motivation: there is no way to work with features granularly, based on nested context, e.g. global > workspace > project > user.
Inspiration:
final class Feature
{
public function __construct(
private string $name,
private ?int $workspace = null,
private ?int $user = null,
) {
}
public function keys(): array
{
$keys = [sprintf('feature:%s', $this->name)];
if ($this->workspace) {
$keys[] = sprintf('feature:%s:workspace:%d', $this->name, $this->workspace);
}
if ($this->user) {
$keys[] = sprintf('feature:%s:user:%d', $this->name, $this->user);
}
if (count($keys) > 1) {
// move up from specific to generic
$keys = array_reverse($keys);
}
return $keys;
}
}
final class Service
{
public function isEnabled(Feature $feature, bool $default = false): bool
{
foreach ($feature->keys() as $key) {
$toggle = Redis::get($key);
if ($toggle === null || $toggle === false) {
continue;
}
return filter_var($toggle, FILTER_VALIDATE_BOOL);
}
return $default;
}
public function toggle(Feature $feature, ?bool $value): void
{
$userFeatureKey = $feature->userKey();
Redis::set($userFeatureKey, $value ?? !$this->isEnabled($feature));
}
}
Need abstraction to adapt it to different storages: MySQL, Redis, PostgreSQL, Bolt, etc.
To do:
Details are here https://github.com/go-yaml/yaml/releases/tag/v3.0.0.
To do:
Steps
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.