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

Document required values of GOMODCACHE (and maybe also GOPATH) #205

Closed
fxedel opened this issue Oct 2, 2023 · 2 comments
Closed

Document required values of GOMODCACHE (and maybe also GOPATH) #205

fxedel opened this issue Oct 2, 2023 · 2 comments

Comments

@fxedel
Copy link

fxedel commented Oct 2, 2023

Apparently, in order to use Go plugins, you have to ensure that both the main binary as well as the plugin binary have been built with the same value of GOMODCACHE (which defaults to $GOPATH/pkg/mod). See golang/go#63230. (Exception: If you use -trimpath as build option for building both binaries. But I assume this is not an option for krakend, as all current plugins would break if krakend introduced that parameter in their build chain).

This was a bit surprising to me, as the error message is also not very helpful (plugin was built with a different version of package golang.org/x/xerrors/internal or similar, since Go apparently considers the two plugin versions to be different because of a different file path ).

So it might be helpful to document the required values in https://www.krakend.io/docs/extending/writing-plugins/:

  • The value of GOMODCACHE should always be /go/pkg/mod (default is GOMODCACHE=$GOPATH/pkg/mod)
  • You usually only have to set this value manually if you use a different GOPATH than the default path /go
  • Tip: You can check go environment variables with go env GOMODCACHE or just go env (list all), since they are not necessarily set in the system's environment variables

Side note: Maybe it would make sense renaming that documentation page to "Building custom plugins"? Since it's more about the build setup and commands, and less about writing the actual code. I found that heading a bit misleading.

@alombarte
Copy link
Member

Hi @fxedel,

Renaming the heading to "building plugins" is a good suggestion. This page was originally about writing plugins, but it was split into multiple pages, and the title stayed.

About the GOMODCACHE value, you are right, and because Go plugins are complex we offer a builder image, so developers do not need to care about this. If you faced this is because you are compiling plugins without any of the builders.

I think that adding this details, while we try that users use the builder, is adding unnecessary information.

@fxedel
Copy link
Author

fxedel commented Jan 28, 2024

Hi @alombarte, actually I was using the builder image, but I added the GOMODCACHE environment variable to speed up the build process. As I'm new to plugin development in Go, I was unaware that this caused the Go plugin to be unusable and it took me some time to identify GOMODCACHE as the cause of failure. Using the builder image actually removes the need for deep knowledge of Go plugins, so I think having a note on this environment variable would indeed be very helpful, especially for builder users.

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