Insert the blank line wsl_v5 requires above `defer` and `go` statements that share no variables with the statement above them. Applied mechanically via `make lint-fix`; the diff is 60 added blank lines and nothing else.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// Package main is the vaultik command-line entry point.
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"runtime/pprof"
|
|
|
|
"sneak.berlin/go/vaultik/internal/cli"
|
|
)
|
|
|
|
func main() {
|
|
// CPU profiling: set VAULTIK_CPUPROFILE=/path/to/cpu.prof
|
|
if cpuProfile := os.Getenv("VAULTIK_CPUPROFILE"); cpuProfile != "" {
|
|
f, err := os.Create(cpuProfile) //nolint:gosec // G304: operator-set path
|
|
if err != nil {
|
|
panic("could not create CPU profile: " + err.Error())
|
|
}
|
|
|
|
defer func() { _ = f.Close() }()
|
|
|
|
err = pprof.StartCPUProfile(f)
|
|
if err != nil {
|
|
panic("could not start CPU profile: " + err.Error())
|
|
}
|
|
|
|
defer pprof.StopCPUProfile()
|
|
}
|
|
|
|
// Memory profiling: set VAULTIK_MEMPROFILE=/path/to/mem.prof
|
|
if memProfile := os.Getenv("VAULTIK_MEMPROFILE"); memProfile != "" {
|
|
defer func() {
|
|
f, err := os.Create(memProfile) //nolint:gosec // G304: operator-set path
|
|
if err != nil {
|
|
panic("could not create memory profile: " + err.Error())
|
|
}
|
|
|
|
defer func() { _ = f.Close() }()
|
|
|
|
runtime.GC() // get up-to-date statistics
|
|
|
|
err = pprof.WriteHeapProfile(f)
|
|
if err != nil {
|
|
panic("could not write memory profile: " + err.Error())
|
|
}
|
|
}()
|
|
}
|
|
|
|
cli.Entry()
|
|
}
|