The idea is to do something only on Linux or MacOS. In C I'd check for OS type roughly in the following way:
#if defined(__linux) || defined(__APPLE__)
printf("OK\n");
#else
printf("NOT OK\n");
#endif
But in Go I have to do the same thing using AND operator instead of OR:
if runtime.GOOS == "linux" && runtime.GOOS == "darwin" {
/* do something*/
} else {
panic(fmt.Sprintf("Not yet implemented for %s", runtime.GOOS))
}
Quick documentation search did not give me any clear explanation on why if statement in Go behaves this way.
Can anyone please explain what am I missing?
Thank you.
Aucun commentaire:
Enregistrer un commentaire