I was trying to figure out a way to expose the some framework packages to a client(another go project) without exposing the source code.It is up to the client to call the methods of framework depending on the requirement
Using Buildmode=archive
- Idea is to build one/many packages using -buildmode=archive and move them to $GOPATH along with one go file for each package with //go:binary-only-package and the package name
Source : Using Binary-Only Packages In Go. When I provide consulting on Go to… | by Shiju Varghese | Medium
Problem : go:binary-only packages are not supported in go latest versions.
Using Buildmode=shared
- Idea is to create a dynamically linked library from where we can access the library code elements at runtime. This uses -linkshared and -buildmode=shared flags.
Sources : Shared library in Go? - Stack Overflow
Problem : -buildmode=shared has its own set of problems and it was throwing runtime errors when we tried to build using -linkshared. There was a proposal to remove -buildmode=shared completely
Using Buildmode=plugin
- Idea is to create a plugin of the main package and load the functions/variables on demand.
Problem : We have to put in more code in the clients to access the functions/variables in the plugin.
Unfortunately, None of these approaches work for my usecase. Please suggest in the comments if there is any other way I could achieve this. Also I’m pretty new to go Please correct me If had understood something incorrectly
Thanks in advance