Hide Golang Code from Exported package

368 views
Skip to first unread message

neeraj singhi

unread,
Dec 7, 2022, 1:09:31 PM12/7/22
to golang-nuts
Hi All,
We are looking for a way to distribute a Golang Package. but We ant to hide the Code which we have written. 
We went Through Creating A DLL to distribute but it crashes at different point while running. As we have distribute to Both linux and windows . And i found that for linux we can use plugin. But the crash for windows dll  after importing the file is concerning for us and its happening at random points in the code also "bad sweepgen in refill".  
If there is any other way to distribute the code without showing the source code please Tell
Thanks
Neeraj

Marcello H

unread,
Dec 8, 2022, 2:43:17 AM12/8/22
to golang-nuts
if you produce an executable, nobody sees the actual Go code.
build it with:
go build -ldflags "-s -w"

or you could try to obfuscate it:
https://github.com/burrowers/garble

or you can make a self-extracting executable


Op woensdag 7 december 2022 om 19:09:31 UTC+1 schreef nsing...@gmail.com:

neeraj singhi

unread,
Dec 12, 2022, 2:56:52 AM12/12/22
to golang-nuts
Actually i need to share it as an sdk. So any way i can share

Brian Candler

unread,
Dec 12, 2022, 3:04:23 AM12/12/22
to golang-nuts
Distribute your library as a grpc server.

neeraj singhi

unread,
Dec 14, 2022, 9:24:19 AM12/14/22
to golang-nuts
Hi is there another  way as we have to package it as a dll or a lib .
But whenever we try using syscall with dll it fails with "bad sweepgen in refill"
Is there any other way where we font create a new executable
thanks

Jason E. Aten

unread,
Dec 23, 2022, 3:47:49 AM12/23/22
to golang-nuts
I've made Windows DLLs work with Go, so I can be done, but I would
strongly suggest that you avoid it. Windows applications expect to be
able to unload their DLLs, and you can never do that with Go.
There are work arounds, (search this form for my previous posts),
but they are ugly and fragile.

So, to save you alot of pain, I would advise you to use a server process
as Brian suggests. You can provide in your SDK code wrapper methods that
can, behind the scene if need be,  start, stop,
and makes RPC calls to that service to serve client requests.
If need be, then the server could eventually remote, or shared over the network.

If that doesn't work, I would just provide the source code to everything.
Reply all
Reply to author
Forward
0 new messages