go.rice
go.rice copied to clipboard
Cannot specify build flags to detect correct file for `rice embed-go`
I have two files:
js_asset_prod.go:
// +build production
package server
import (
"github.com/GeertJohan/go.rice"
)
var javascriptAssetRiceBox = rice.MustFindBox("./js/prod").HTTPBox() // <--- prod path
and js_asset_dev.go:
// +build !production
package server
import (
"github.com/GeertJohan/go.rice"
)
var javascriptAssetRiceBox = rice.MustFindBox("./js/dev").HTTPBox() // <-- dev path
And when I run rice -v -i ./server/ embed-go I get output like:
2015/05/06 23:50:17 skipping file "~/server/js-dev.rice-box.go"
2015/05/06 23:50:17 scanning file "~/server/js_asset_dev.go"
2015/05/06 23:50:17 found box "js/dev"
2015/05/06 23:50:17 scanning file "~/server/server.go"
2015/05/06 23:50:17
2015/05/06 23:50:17 embedding box 'js/dev'
2015/05/06 23:50:17 to file js-dev.rice-box.go
2015/05/06 23:50:17 includes dir: ''
2015/05/06 23:50:17
2015/05/06 23:50:17 rice finished successfully
It appears that rice does not recognize js_asset_prod.go because it has an opt-in build flag, and in go.rice/flags.go, it uses build.ImportDir which does not support adding build flags (and the rice CLI does not support adding build flags either).
There could be a new flag in the rice tool, --build-tag, that can be specified multiple times for multiple tags, and use ImportDir as a method from build.Context which we create with the provided --build-tag values. Would you be willing to create this solution and PR?