Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous error message on required #51

Open
prochac opened this issue Jan 21, 2020 · 4 comments
Open

Ambiguous error message on required #51

prochac opened this issue Jan 21, 2020 · 4 comments

Comments

@prochac
Copy link

prochac commented Jan 21, 2020

Hi, thanks for this project.
We have only one painfull issue with this library.
We use this for web services configuration and the config struct is nested and contains a lot of URLs to other services.

Sometimes we forgot to add secret to Vault, but error message is not much helpfull.

Here is our common usage
https://play.golang.org/p/XdV_kGtkQn7

package main

import (
	"fmt"
	"log"

	"github.com/jinzhu/configor"
)

type Config struct {
	InputService struct {
		URL string `env:"IN_SERVICE_URL" required:"true"`
	}
	OutputService struct {
		URL string `env:"OUT_SERVICE_URL" required:"true"`
	}
}

func main() {
	var config Config
	if err := configor.Load(&config); err != nil {
		log.Fatal(err) // URL is required, but blank
	}

	fmt.Println("Your config:", config)
}
@lukasaron
Copy link

The error is correct I would recommend to change the name of the field from URL into something more specific. The error will be more helpful then.

@prochac
Copy link
Author

prochac commented May 28, 2020

Ok, but it's anoying to have to use

config.InputService.InputServiceURL

instead of

config.InputService.URL

I planed to do a pull request for this issue but than I realized that even full name is not what I want.

InputService.URL is required, but blank

What I expect is more like

IN_SERVICE_URL variable is required, but blank

So I'm not using this lib anymore :) Not because it's bad.
But because anything simpler, for environment variables only, is enough for me.

@lukasaron
Copy link

lukasaron commented May 28, 2020

You are making assumptions based on the env variable in the tag. Such variable might be also empty when this value is filled from other source than ENV variable.

Existing logic returns the name of the field which is required and its value is empty (not defined in any source).

Based on your code I would suggest naming the field: InputURL or InURL and same format for output to distinguish between them.

@prochac
Copy link
Author

prochac commented May 28, 2020

Yeah, no doubt.

As I sayed, I don't use this lib anymore.

Less is more and it works for me.
I need to have the env vars only, following https://12factor.net/config, so I made a switch.
https://play.golang.org/p/ABZ7CuywNKQ
or good ol' os.Getenv and os.LookupEnv.

And instead of .env, yaml, toml, ... files you can use shell file for sourcing the dev environment.
And without adding the extra complexity to app.
$ . ./dev-env.sh
simple as pie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants