I was watching one of your streams the other day you were playing around with environment variables. I had an idea for a simple validation api that I think could be quite nice for them. Its inspired by what T3.gg does.
I have a working example by extending the validation library, I'm happy to contribute a PR but wanted to first make sure its something you like for the vision of the project.
The idea is to have a global Env struct with all the environment variables and validation for them. With this we achieve:
Auto complete when using env variables
Crashing the program on startup if environment variables are missing
There is still a little wackiness with the api since you can pass v.Required and then .default() together which is weird.
I also think there is space to somehow convert env variables into things that are not strings in this step. For example for a server you might have a max connections env variable that is actually an int (since os.Getenv always returns a string)
Hey!
I was watching one of your streams the other day you were playing around with environment variables. I had an idea for a simple validation api that I think could be quite nice for them. Its inspired by what T3.gg does.
I have a working example by extending the validation library, I'm happy to contribute a PR but wanted to first make sure its something you like for the vision of the project.
The idea is to have a global Env struct with all the environment variables and validation for them. With this we achieve:
This is what the API would look like:
There is still a little wackiness with the api since you can pass v.Required and then .default() together which is weird.
I also think there is space to somehow convert env variables into things that are not strings in this step. For example for a server you might have a max connections env variable that is actually an int (since os.Getenv always returns a string)