Golang Notes: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
(Created page with "== Questions == import prefixes what ar ethye: * nothing * "." * "_" == Grab bag == === Environment Variables === https://stackoverflow.com/questions/40326540/how-to-ass...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
== Questions == | == Questions == | ||
import prefixes what | import prefixes what are they: | ||
* nothing | * nothing | ||
* "." | * "." | ||
* "_" | * "_" | ||
== Grab bag == | == Grab bag == | ||
Line 31: | Line 31: | ||
} | } | ||
</pre> | </pre> | ||
=== runtime.NumCPU === | |||
numcpu.go | |||
<pre> | |||
package main | |||
import ( | |||
"fmt" | |||
"runtime" | |||
) | |||
func main() { | |||
fmt.Println(runtime.NumCPU()) | |||
} | |||
</pre> | |||
go run numcpu.go |
Latest revision as of 21:00, 30 July 2020
Questions
import prefixes what are they:
- nothing
- "."
- "_"
Grab bag
Environment Variables
https://stackoverflow.com/questions/40326540/how-to-assign-default-value-if-env-var-is-empty
func getenv(key, fallback string) string { value := os.Getenv(key) if len(value) == 0 { return fallback } return value }
func getEnv(key, fallback string) string { if value, ok := os.LookupEnv(key); ok { return value } return fallback }
runtime.NumCPU
numcpu.go
package main import ( "fmt" "runtime" ) func main() { fmt.Println(runtime.NumCPU()) }
go run numcpu.go