This removes the requirement to call fmsg.Exit on every exit path, and enables direct use of the "log" package. However, fmsg.BeforeExit is still encouraged when possible to catch exit on suspended output. Signed-off-by: Ophestra <cat@gensokyo.uk>
26 lines
356 B
Go
26 lines
356 B
Go
package internal
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
executable string
|
|
executableOnce sync.Once
|
|
)
|
|
|
|
func copyExecutable() {
|
|
if name, err := os.Executable(); err != nil {
|
|
log.Fatalf("cannot read executable path: %v", err)
|
|
} else {
|
|
executable = name
|
|
}
|
|
}
|
|
|
|
func MustExecutable() string {
|
|
executableOnce.Do(copyExecutable)
|
|
return executable
|
|
}
|