package config import ( "fmt" "os" "time" ) const TimeFormat = "2006-01-02/15:04:05" const BufSize = 1024 const IoTimeout = 5 * time.Second func GetSystemSocketPath() string { return "/run/tunnel/socket" } func getuid() int { uid := os.Getuid() if uid < 0 { panic("os.Getuid() returns negative uid") } return uid } func runAsRoot() bool { uid := os.Getuid() if uid < 0 { panic("os.Getuid() returns negative uid") } return uid == 0 } func GetSocketPath() string { if uid := getuid(); uid == 0 { return GetSystemSocketPath() } else { return fmt.Sprintf("/run/user/%d/tunnel/socket", uid) } } func GetConfigPath() string { if uid := getuid(); uid == 0 { return "/etc/tunnel.conf" } else if s, err := os.UserConfigDir(); err == nil { return s + "/tunnel/config" } else { return "" } }