Unable to import CLI in Go 1.6+ - fails to compile due to i18n.TranslateFunc
I recently checked out the CF Blue/Green Deployment plugin and tried to build it with Go 1.6+. When I tried, I got the following error:
./main.go:173: cannot assign "github.com/nicksnyder/go-i18n/i18n".TranslateFunc to "github.com/cloudfoundry/cli/cf/i18n".T (type "github.com/cloudfoundry/cli/vendor/github.com/nicksnyder/go-i18n/i18n".TranslateFunc) in multiple assignment
The issue is that the behaviour of Go with respect to the vendor directory has changed in 1.6, and since this project has a vendor directory checked into source control, anything that imports it is liable to break, unless it's relying purely on interfaces.
Now, maybe the project I'm using is doing something wrong - the exact line of code that fails is:
// T needs to point to a translate func, otherwise cf internals blow up
i18n.T, _ = go_i18n.Tfunc("")
If that's the case, I'll close this issue and raise one on the other project.
We have created an issue in Pivotal Tracker to manage this:
https://www.pivotaltracker.com/story/show/126134685
The labels on this github issue will be updated when the story is started.
Hi @ipsi, checking in a vendor directory is standard practice for many projects and should not be considered the source of the problem. After looking at blue-green-deploy it is odd that the T function is getting set in the main function. That shouldn't need to happen unless they plan on changing the T function to do their own translations. For testing since they are making a call into cf code then they do need to assign a value to the T function because it is initialized with an init().
You might submit a PR to blue-green-deploy. We would suggest the following changes:
main.go:170
- // T needs to point to a translate func, otherwise cf internals blow up
- i18n.T, _ = go_i18n.Tfunc("")
manifest_test.go:15
+type localeGetter struct{}
+
+func (l localeGetter) Locale() string {
+ return "en-us"
+}
+
var _ = Describe("Manifest reader", func() {
// testing code that calls into cf cli requires T to point to a translate func
- i18n.T, _ = go_i18n.Tfunc("")
+ i18n.T = i18n.Init(localeGetter{})
We're going to close this issue. If you think we have overlooked something and it is still a CF CLI problem feel free to re open it.
- @challiwill & @nickwei84
Thanks, @nickwei84. You said,
That shouldn't need to happen unless they plan on changing the T function to do their own translations.
But it it's currently impossible for a plugin to change the T function in Go 1.6+, as it's been vendored. If a plugin changing the T function is not supported, then that's perfectly fair. If it is supposed to be supported, then I think there's a bit of a problem.
@ipsi that's true. It's currently not designed to be changed.
Thanks @ipsi, @nickwei84, and @challiwill. We've tried out the suggested fix, and everything compiles beautifully, but at runtime we get this:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6c2da]
on
sliceErr := fmt.Errorf(T("Expected {{.PropertyName}} to be a list of strings.", map[string]interface{}{"PropertyName": key}))
in manifest.go. So it looks like the right fix isn't to completely delete the line in main.go containing the assignment, but instead to call i18n.Init([SOME SUITABLE LOCALE]) (like the suggested test change, but with a more generic locale). If we've still got the wrong end of the stick, feedback welcome. :)