markbates / pkger

Embed static files in Go binaries (replacement for gobuffalo/packr)
MIT License
1.19k stars 60 forks source link

[Bug] pkger.Include() not accepted const or var as argument for name #60

Closed koddr closed 4 years ago

koddr commented 4 years ago

Hi!

I catch strange bug: if I specify name arg on pkger.Include() by var (or const), it folder/file is not accepted (e.g. not embed to binary). For example:

package main

import (
    "github.com/markbates/pkger"
)

var (
    configFolder string = "/configs"
)

// OR:
//
// const (
//  configFolder string = "/configs"
// )

func main() {
    // Embed ./configs folder
    pkger.Include(configFolder)

    // ...

But, if I specify name as simple string, like pkger.Include("/configs"), all okay. What I miss? Help to understand please.

markbates commented 4 years ago

That’s not a bug. That’s expected. Pkger uses static analysis tools to figure out what it includes. Static analysis can’t determine dynamic values, only static ones, like hard coded strings.

-- Mark Bates

On Dec 31, 2019, at 7:00 AM, Vic Shóstak notifications@github.com wrote:

 Hi!

I catch strange bug: if I specify name arg on pkger.Include() by var (or const), it folder/file is not accepted (e.g. not embed to binary). For example:

package main

import ( "github.com/markbates/pkger" )

var ( configFolder string = "/configs" )

// OR: // // const ( // configFolder string = "/configs" // )

func main() { // Embed ./configs folder pkger.Include(configFolder)

// ... But, if I specify name as simple string, like pkger.Include("/configs"), all okay. What I miss? Help to understand please.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

qmuntal commented 4 years ago

@markbates if a string is defined as const its value could be determined by a static analysis, as it cannot change at runtime, therefore this issue should still be opened.