Exposing go packages as libraries without exposing source code

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

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 :slight_smile: Please correct me If had understood something incorrectly

Thanks in advance

Source for plugin part : https://technobeans.com/2019/03/05/plugins-in-go/
Proposal to remove -buildmode=shared : https://github.com/golang/go/issues/47788

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.