They will always be lowercase, as the values are all defined in the code
const GOOS = `android`
const GOOS = `darwin`
const GOOS = `dragonfly`
const GOOS = `freebsd`
const GOOS = `linux`
const GOOS = `nacl`
const GOOS = `netbsd`
const GOOS = `openbsd`
const GOOS = `plan9`
const GOOS = `solaris`
const GOOS = `windows`
But it's usually better to rely on build constraints rather than
conditionals at runtime.
On Monday, August 7, 2017 at 5:00:24 PM UTC-4, Eric Brown wrote:
>
> This may be a completely stupid or trivial question; however...
>
> I currently use this on some old code I'm working on and trying to clean
> things up:
>
> switch os := strings.ToLower(runtime.GOOS); os {
> case "windows":
> // do windows stuff here
> case "linux":
> // do linux stuff here
>
> default:
> // do default stuff here
>
> }
>
>
> I hate to import the entire strings package just to ensure that switch
> will work. Does anybody know if runtime.GOOS will always return a
> lowercase value so I don't have to import the strings package just for this
> single check? All I can find is that GOOS returns (sys
> <https://golang.org/pkg/runtime/internal/sys/>.GOOS
> <https://golang.org/pkg/runtime/internal/sys/#GOOS>)...
> I'd rather be safe than sorry.
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.