Golang Notes: Difference between revisions

From Federal Burro of Information
Jump to navigationJump to search
No edit summary
 
Line 1: Line 1:
== Questions ==
== Questions ==


import prefixes what ar ethye:
import prefixes what are they:


* nothing
* nothing
* "."
* "."
* "_"  
* "_"


== Grab bag ==
== Grab bag ==

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