common

package
v0.9.10 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommandStart              = ""
	CommandValidate           = "validate"
	CommandListConfigs        = "ls-config"
	CommandListRoutes         = "ls-routes"
	CommandListIcons          = "ls-icons"
	CommandReload             = "reload"
	CommandDebugListEntries   = "debug-ls-entries"
	CommandDebugListProviders = "debug-ls-providers"
	CommandDebugListMTrace    = "debug-ls-mtrace"
)
View Source
const (
	ConnectionTimeout = 5 * time.Second
	DialTimeout       = 3 * time.Second
	KeepAlive         = 60 * time.Second
)
View Source
const (
	DotEnvPath        = ".env"
	DotEnvExamplePath = ".env.example"

	ConfigBasePath         = "config"
	ConfigFileName         = "config.yml"
	ConfigExampleFileName  = "config.example.yml"
	ConfigPath             = ConfigBasePath + "/" + ConfigFileName
	HomepageJSONConfigPath = ConfigBasePath + "/.homepage.json"
	IconListCachePath      = ConfigBasePath + "/.icon_list_cache.json"
	IconCachePath          = ConfigBasePath + "/.icon_cache.json"

	MiddlewareComposeBasePath = ConfigBasePath + "/middlewares"

	ComposeFileName        = "compose.yml"
	ComposeExampleFileName = "compose.example.yml"

	ErrorPagesBasePath = "error_pages"
)
View Source
const (
	HealthCheckIntervalDefault = 5 * time.Second
	HealthCheckTimeoutDefault  = 5 * time.Second

	WakeTimeoutDefault = "30s"
	StopTimeoutDefault = "30s"
	StopMethodDefault  = "stop"
)
View Source
const DockerHostFromEnv = "$DOCKER_HOST"
View Source
const HeaderCheckRedirect = "X-Goproxy-Check-Redirect"

Variables

View Source
var (
	IsTest       = GetEnvBool("TEST", false) || strings.HasSuffix(os.Args[0], ".test")
	IsDebug      = GetEnvBool("DEBUG", IsTest)
	IsTrace      = GetEnvBool("TRACE", false) && IsDebug
	IsProduction = !IsTest && !IsDebug

	EnableLogStreaming = GetEnvBool("LOG_STREAMING", true)
	DebugMemLogger     = GetEnvBool("DEBUG_MEM_LOGGER", false) && EnableLogStreaming

	ProxyHTTPAddr,
	ProxyHTTPHost,
	ProxyHTTPPort,
	ProxyHTTPURL = GetAddrEnv("HTTP_ADDR", ":80", "http")

	ProxyHTTPSAddr,
	ProxyHTTPSHost,
	ProxyHTTPSPort,
	ProxyHTTPSURL = GetAddrEnv("HTTPS_ADDR", ":443", "https")

	APIHTTPAddr,
	APIHTTPHost,
	APIHTTPPort,
	APIHTTPURL = GetAddrEnv("API_ADDR", "127.0.0.1:8888", "http")

	PrometheusEnabled = GetEnvBool("PROMETHEUS_ENABLED", false)

	APIJWTSecret   = decodeJWTKey(GetEnvString("API_JWT_SECRET", ""))
	APIJWTTokenTTL = GetDurationEnv("API_JWT_TOKEN_TTL", time.Hour)
	APIUser        = GetEnvString("API_USER", "admin")
	APIPassword    = GetEnvString("API_PASSWORD", "password")

	// OIDC Configuration.
	OIDCIssuerURL     = GetEnvString("OIDC_ISSUER_URL", "")
	OIDCLogoutURL     = GetEnvString("OIDC_LOGOUT_URL", "")
	OIDCClientID      = GetEnvString("OIDC_CLIENT_ID", "")
	OIDCClientSecret  = GetEnvString("OIDC_CLIENT_SECRET", "")
	OIDCRedirectURL   = GetEnvString("OIDC_REDIRECT_URL", "")
	OIDCScopes        = GetEnvString("OIDC_SCOPES", "openid, profile, email")
	OIDCAllowedUsers  = GetCommaSepEnv("OIDC_ALLOWED_USERS", "")
	OIDCAllowedGroups = GetCommaSepEnv("OIDC_ALLOWED_GROUPS", "")
)
View Source
var (
	WellKnownHTTPPorts = map[string]bool{
		"80":   true,
		"8000": true,
		"8008": true,
		"8080": true,
		"3000": true,
	}

	ServiceNamePortMapTCP = map[string]int{
		"mssql":            1433,
		"mysql":            3306,
		"mariadb":          3306,
		"postgres":         5432,
		"rabbitmq":         5672,
		"redis":            6379,
		"memcached":        11211,
		"mongo":            27017,
		"minecraft-server": 25565,

		"ssh":  22,
		"ftp":  21,
		"smtp": 25,
		"dns":  53,
		"pop3": 110,
		"imap": 143,
	}

	ImageNamePortMap = func() (m map[string]int) {
		m = make(map[string]int, len(ServiceNamePortMapTCP)+len(imageNamePortMap))
		for k, v := range ServiceNamePortMapTCP {
			m[k] = v
		}
		for k, v := range imageNamePortMap {
			m[k] = v
		}
		return
	}()
)

Functions

func GetAddrEnv

func GetAddrEnv(key, defaultValue, scheme string) (addr, host, port, fullURL string)

func GetCommaSepEnv

func GetCommaSepEnv(key string, defaultValue string) []string

func GetDurationEnv

func GetDurationEnv(key string, defaultValue time.Duration) time.Duration

func GetEnv

func GetEnv[T any](key string, defaultValue T, parser func(string) (T, error)) T

func GetEnvBool

func GetEnvBool(key string, defaultValue bool) bool

func GetEnvString

func GetEnvString(key string, defaultValue string) string

Types

type Args

type Args struct {
	Command string
}

func GetArgs

func GetArgs() Args

Jump to

Keyboard shortcuts

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