runtime

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Domain  = version.Domain
	Block   = true
	Trace   = false
	Addr    = ":8080"
	Project = "lava"
	Level   = "debug"
	Mode    = RunModeDev

	// DeviceID 主机设备ID
	DeviceID = xerror.ExitErr(machineid.ID())

	Signal os.Signal = syscall.Signal(0)

	// Pwd 当前目录
	Pwd = xerror.ExitErr(os.Getwd()).(string)

	// Hostname 主机名
	Hostname = utils.FirstNotEmpty(
		func() string { return os.Getenv("HOSTNAME") },
		func() string {
			var h, err = os.Hostname()
			xerror.Exit(err)
			return h
		},
	)

	// Namespace 命名空间
	Namespace = utils.FirstNotEmpty(
		func() string { return os.Getenv("NAMESPACE") },
		func() string { return os.Getenv("POD_NAMESPACE") },
		func() string {
			if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
				if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
					return ns
				}
			}
			return ""
		},
	)

	// Homedir the home directory for the current user
	Homedir = utils.FirstNotEmpty(
		homedir.HomeDir,
		func() string {
			var h, err = dir.Dir()
			xerror.Exit(err)
			return h
		},
		func() string { return "." },
	)
)

默认的全局配置

View Source
var RunModeValue = map[string]int32{
	"dev":     0,
	"test":    1,
	"stag":    2,
	"prod":    3,
	"release": 4,
	"unknown": 5,
}

Functions

func GetVersion

func GetVersion() map[string]interface{}

func IsDev

func IsDev() bool

func IsProd

func IsProd() bool

func IsRelease

func IsRelease() bool

func IsStag

func IsStag() bool

func IsTest

func IsTest() bool

func Name

func Name() string

Types

type RunMode

type RunMode int32
const (
	RunModeDev     RunMode = 0
	RunModeTest    RunMode = 1
	RunModeStag    RunMode = 2
	RunModeProd    RunMode = 3
	RunModeRelease RunMode = 4
	RunModeUnknown RunMode = 5
)

func (RunMode) String

func (x RunMode) String() string

Jump to

Keyboard shortcuts

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