Cannot compile for other GOOS
hryamzik opened this issue · comments
Roman Belyakovsky commented
Of course I make keychain calls only on darwin but it's a runtime check for runtime.GOOS
. I'd like to be able to compile for other OSes as well.
Deleted user commented
I fixed it using // +build dragonfly freebsd windows linux netbsd openbsd solaris
on one file and // +build darwin
at the top of the other. And have a common file calling a function which exists in both.
package util
// this is password.go
import ()
// GetPassword for user, if possible use system password storage
func GetPassword(prompt, user, provider string) (string, error) {
return getPassword(prompt, user, provider)
}
and then two files password_darwin.go
// +build darwin
package util
import (
keychain "github.com/keybase/go-keychain"
)
// GetPassword for user, if possible use system password storage
func getPassword(prompt, user, provider string) (string, error) {
[macOS Code....]
}
and password_other.go
// +build dragonfly freebsd windows linux netbsd openbsd solaris
package util
import (
)
// GetPassword for user
func getPassword(prompt, user, provider string) (string, error) {
[code run on other system than macOS ....]
}
Fred Akalin commented
Yeah, that's how we use this package, too, and how we recommend how to use this package for cross-platform projects.