Code Monkey home page Code Monkey logo

config's People

Contributors

kamilsk avatar

Watchers

 avatar  avatar

config's Issues

feature: decode from string

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:

  • Find way to decode "multi-value" header. Is ; the separator?

input: improve config experience with Viper and Cobra

Motivation: there is no generic way to work with "prefixed" embedded structures. It leads to code duplication and makes it dirty.

Scope:

feature: find way to build flexible nested feature set

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:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.