If you are happy for the compile-time data to be in a file, rather than 
supplied as flags to the build command, then
//go:embed
should do the trick.

https://pkg.go.dev/embed

On Thursday, 1 December 2022 at 09:39:38 UTC hey...@gmail.com wrote:

> I'm writing a command line program in go, and it needs to access some 
> predefined external files like /usr/lib/name/file. What would be a good way 
> to allow specify the constant path in compile time?
>
> I see two options:
>
> 1. go generate
> 2. -ldflags="-X 'main.Path=..."
>
> Both seem to be flawed. For #1, the blog clearly stated that it's designed 
> for package author, and not for clients (and go generate doesn't support 
> passing arguments to //go:generate anyways). For #2, the path can't be a 
> constant.
>
> Is there a convention on how this problem should be solved or external 
> paths should always be passed in as arguments in go?
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/32648ea6-5be7-480e-a432-eb4f92860272n%40googlegroups.com.

Reply via email to