Coder Social home page Coder Social logo

Envvar 'Allowed Values' Enum? about envvars HOT 3 OPEN

flemay avatar flemay commented on June 13, 2024 1
Envvar 'Allowed Values' Enum?

from envvars.

Comments (3)

flemay avatar flemay commented on June 13, 2024

Hi @andyt10 ! Thanks for creating a new issue. I did think about it before and I am not sure what is the best solution. We can start with string values but I think eventually, one will want types and different validations. A bit like AWS parameters. Is it where envvars should be headed?

I also wouldn't mind having value validation based on regex. Introducing this feature would probably be simple as well as providing more options to the user.

Lately, I have been playing with CUE. You can see my spike in _cuelang.

from envvars.

andyt10 avatar andyt10 commented on June 13, 2024

Hey @flemay I think regex validation could also be a useful feature, for similar reasons I'd like to specify a list of allowed.

I also think you might be right in saying that extending the functionality of envvars might be helpdful/desired using something like CUE . For something 'next version' like that I'd perhaps picture myself packaging up a standard library of envvar/config type definitions for use in multiple projects....somehow...but that's a bit beyond what I'm considering right now.😄

For me regex/string enum validation would suit the majority of use cases that come to mind for making sure a value conforms.
I sort of pictured something like above:

      - name: SERVER_ENV
      .....
      .....
      values:
          - dev
          - qa
          - preprod
          - prod

which I think would also work similarly for regexes:

      - name: SERVER_ENV
      .....
      .....
      matchRegex: ^some[0-9]{1,}value$

where both options would be mutually exclusive (defining both would be invalid)

from envvars.

flemay avatar flemay commented on June 13, 2024

What I meant is that values list can be written using regex :)

package main

import (
	"fmt"
	"log"
	"regexp"
)

func main() {
	r, err := regexp.Compile("(^dev$)|(^qa$)|(^preprod$)|(^prod$)")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(r.MatchString("qa"))         // true
	fmt.Println(r.MatchString("preprod"))    // true
	fmt.Println(r.MatchString("production")) // false
}

from envvars.

Related Issues (6)

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.