runenv

package
v0.35.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package runenv locates the run, install, log and config paths of the process, reports its uptime and serves pprof on request.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConfPath overrides the install path when set.
	ConfPath string
)
View Source
var OnOpenWrt = sync.OnceValue(func() bool {
	if runtime.GOOS != "linux" {
		return false
	}
	_, err := os.Stat("/etc/openwrt_release")
	return err == nil
})

OnOpenWrt reports whether this is an OpenWrt system. Its devices often have little memory, /var is a RAM disk and /etc is flash, so nps and npc log nothing there unless told to, as the OpenWrt packages do.

Functions

func FileExists

func FileExists(name string) bool

FileExists reports whether the named file or directory exists.

func GetAppPath

func GetAppPath() string

GetAppPath Get the absolute path to the running directory

func GetConfigPath

func GetConfigPath() string

GetConfigPath config file path

func GetEnvMap

func GetEnvMap() map[string]string

GetEnvMap get env

func GetInstallPath

func GetInstallPath() string

GetInstallPath Different systems get different installation paths

func GetLogPath

func GetLogPath() string

GetLogPath interface log file path

func GetNpcLogPath

func GetNpcLogPath() string

GetNpcLogPath interface npc log file path

func GetPath

func GetPath(filePath string) string

func GetRunPath

func GetRunPath() string

GetRunPath Get the currently selected configuration file directory For non-Windows systems, select the /etc/nps as config directory if exist, or select ./ windows system, select the C:\Program Files\nps as config directory if exist, or select ./

func GetRunSecs

func GetRunSecs() int64

func GetRunTime

func GetRunTime() string

func GetStartTime

func GetStartTime() int64

func InitPProfByAddr

func InitPProfByAddr(addr string)

InitPProfByAddr serves pprof on addr, host:port; an empty host is the loopback address, as the profiles show the process's memory.

func IsWindows

func IsWindows() bool

IsWindows Determine whether the current system is a Windows system?

func LogDefaults

func LogDefaults(typ string, size, files int) (string, int, int)

LogDefaults returns the default log mode, file size in MB and number of files: off, 1 and 1 on OpenWrt, else typ, size and files.

func ResolvePath

func ResolvePath(path string) string

func SetSoftMemoryLimit added in v0.35.4

func SetSoftMemoryLimit() int64

SetSoftMemoryLimit gives the Go runtime a soft memory limit of half the total memory on a small device, so that the collector works harder before the system runs out of memory; the limit fails no allocation. GOMEMLIMIT, when set, wins. It returns the limit set, 0 for none.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL