https://tuhrig.de/how-to-know-you-are-inside-a-docker-container/
https://github.com/sindresorhus/is-docker/blob/master/index.js
| package main | |
| import ( | |
| "bufio" | |
| "io/ioutil" | |
| "os/signal" | |
| //"syscall" | |
| "fmt" | |
| "log" | |
| "os" |
| git config --global credential.modalPrompt false |
| ```go | |
| func isNil(i interface{}) bool { | |
| return i == nil || reflect.ValueOf(i).IsNil() | |
| } | |
| ``` | |
| better: | |
| ```go | |
| func isNilFixed(i interface{}) bool { |
| package main | |
| import ( | |
| "flag" | |
| "fmt" | |
| "log" | |
| "os" | |
| "runtime/pprof" | |
| "strconv" | |
| "sync" |
| # human readable /proc/net/netstat | |
| # https://sa-chernomor.livejournal.com/9858.html | |
| cat /proc/net/netstat | \ | |
| awk '(f==0) { i=1; while ( i<=NF) {n[i] = $i; i++ }; f=1; next} \ | |
| (f==1){ i=2; while ( i<=NF){ printf "%s = %d\n", n[i], $i; i++}; f=0} ' |
| package main | |
| /* | |
| #include <unistd.h> | |
| */ | |
| import "C" | |
| import ( | |
| "fmt" | |
| "time" | |
| ) |
| package main | |
| import ( | |
| "os" | |
| "os/exec" | |
| ) | |
| func Start(args ...string) (p *os.Process, err error) { | |
| if args[0], err = exec.LookPath(args[0]); err == nil { | |
| var procAttr os.ProcAttr |
| package main | |
| import ( | |
| "flag" | |
| "fmt" | |
| "log" | |
| "os" | |
| "os/signal" | |
| "syscall" | |
| ) |
| /* | |
| How to simulate classes and virtual methods in Go. | |
| */ | |
| package main | |
| import . "fmt" | |
| type A struct { | |
| // Set My to outermost object (most derived class) after constructing. |