running

package
v2.0.0-beta.13 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Env      = redant.StringOf(lo.ToPtr("dev"))
	Debug    = redant.BoolOf(lo.ToPtr(false))
	HttpPort = redant.Int64Of(lo.ToPtr(int64(8080)))
	GrpcPort = redant.Int64Of(lo.ToPtr(int64(50051)))
	Project  = version.Project

	// InstanceID service id
	InstanceID = xid.New().String()

	DeviceID = InstanceID

	Version = version.Version

	CommitID = version.CommitID

	Pwd = assert.Exit1(os.Getwd())

	// LocalIP the local IP address of the current service
	LocalIP = netutil.GetLocalIP()

	Hostname = strutil.FirstFnNotEmpty(
		func() string { return env.Get("HOSTNAME") },
		func() string { return assert.Exit1(os.Hostname()) },
	)

	// Namespace K8s namespace
	Namespace = strutil.FirstFnNotEmpty(
		func() string { return env.Get("NAMESPACE") },
		func() string { return env.Get("POD_NAMESPACE") },
		func() string {
			file := "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
			if pathutil.IsNotExist(file) {
				return ""
			}

			return strings.TrimSpace(string(assert.Exit1(os.ReadFile(file))))
		},
	)

	Domain = version.Domain

	DebugFlag = redant.Option{
		Flag:        "debug",
		Description: "enable debug mode",
		Value:       Debug,
		Default:     Debug.String(),
		Category:    "system",
		Envs:        []string{env.Key("enable_debug"), env.Key("debug")},
		Action: func(val pflag.Value) error {
			env.Set("enable_debug", val.String())
			env.Set("debug", val.String())
			return debugs.Enabled.Set(val.String())
		},
	}

	EnvFlag = redant.Option{
		Flag:        "env",
		Description: "running env, dev,test,stage,prod",
		Value:       Env,
		Default:     Env.String(),
		Category:    "system",
		Envs:        []string{env.Key("env"), env.Key("run_env")},
		Action: func(val pflag.Value) error {
			env.Set("env", val.String())
			env.Set("run_env", val.String())
			return nil
		},
	}

	GrpcPortFlag = redant.Option{
		Flag:        "grpc-port",
		Description: "service grpc port",
		Value:       GrpcPort,
		Default:     GrpcPort.String(),
		Category:    "system",
		Envs:        []string{env.Key("server_grpc_port")},
		Action: func(val pflag.Value) error {
			env.Set("server_grpc_port", val.String())
			return nil
		},
	}

	// HttpPortFlag http port
	HttpPortFlag = redant.Option{
		Flag:        "http-port",
		Description: "service http port",
		Value:       HttpPort,
		Category:    "system",
		Default:     HttpPort.String(),
		Envs:        []string{env.Key("server_http_port")},
		Action: func(val pflag.Value) error {
			env.Set("server_http_port", val.String())
			return nil
		},
	}

	ConfFlag = redant.Option{
		Flag:        "config",
		Shorthand:   "c",
		Description: "config path",
		Default:     config.GetConfigPath(),
		Value:       redant.StringOf(lo.ToPtr(config.GetConfigPath())),
		Category:    "system",
		Envs:        []string{env.Key("config_path")},
		Action: func(val pflag.Value) error {
			config.SetConfigPath(val.String())
			env.Set("config_path", val.String())
			return nil
		},
	}
)

default global variables

Functions

func CheckVersion

func CheckVersion()

CheckVersion 检查版本信息

func GetSysInfo

func GetSysInfo() map[string]string

Types

This section is empty.

Jump to

Keyboard shortcuts

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