On Thu, Dec 01, 2022 at 06:21:37PM +0800, Glen Huang wrote:
> Const is the ideal choice, but how do users of my program specify the path when
> they compile it?
I don't think this is something for which there is a "canonical Go
way", so I'd say something like a tiny makefile that sets the path
with the PREFIX environment variable, passing that to -ldflags as
you suggested.
> Using var loses the guarantee that the path won’t be changed, and the go
> compiler can no longer optimize as much I presume?
I don't think it being var rather than const is going to be an
optimization bottleneck. But if it really was important, then you
could use a makefile to insert / overwrite a line with sed or
similar, keeping some sensible default working for users who
eschewed the makefile and just used 'go install' or whatever.