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

Fatal error, mongodb initialization failed: open /home/user/work/pkg/mod/github.com/zebresel-com/[email protected]+incompatible/locals.json: no such file or directory" #30

Open
piyushgupte opened this issue Nov 10, 2020 · 1 comment

Comments

@piyushgupte
Copy link

I have built an executable of my go application which uses zebresel-com/mongodm and am trying to deploy it in docker container, but I am getting the following error.It is working great on my linux box but it fails when I try to deploy it inside docker.
" initialization failed: open /home/myuser/work/pkg/mod/github.com/zebresel-com/[email protected]+incompatible/locals.json: no such file or directory"
Steps to reproduce:

  1. Create a go executable of work repo which is using zebresel-com/mongodm
  2. Copy the executable in docker env via Docker copy command through Dockerfile
@vhbfernandes
Copy link

Nearly one year later, I've got this problem too, digging it up I found out what it is

Once you generated the binary file, it still looks for this locals.json file to start the connection; The simple solution was to embed it as a string in my connection file, something like this:

var localMapStr = `
{
  "en-US": {
    "validation.field_required": "Field '%s' is required.",
    "validation.field_invalid": "Field '%s' has an invalid value.",
    "validation.field_invalid_id": "Field '%s' contains an invalid object id value.",
    "validation.field_minlen": "Field '%s' must be at least %v characters long.",
    "validation.field_maxlen": "Field '%s' can be maximum %v characters long.",
    "validation.entry_exists": "%s already exists for value '%v'.",
    "validation.field_not_exclusive": "Only one of both fields can be set: '%s'' or '%s'.",
    "validation.field_required_exclusive": "Field '%s' or '%s' required."
  }
}
`
var localMap map[string]map[string]string
json.Unmarshal([]byte(localMapStr), &localMap)
dbConfig := &mongodm.Config{
	DatabaseHosts: []string{os.Getenv("MONGODB_HOST")},
	DatabaseName: os.Getenv("MONGODB_DATABASE"),
	Locals:       localMap["en-US"],
}

Not really the best solution out there, but this package seems a little out of date anyway

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