common

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package common provides several common utilities for other packages.

Index

Constants

This section is empty.

Variables

View Source
var URLFriendlyCharactersRegex = regexp.MustCompile(`^[A-Za-z0-9\-_\.~]{1,253}$`)

URLFriendlyCharactersRegex - safe characters for friendly url, rfc3986 section 2.3

Functions

func BackupAndCleanDir

func BackupAndCleanDir(dir string) error

BackupAndCleanDir cleans old stuff in both dir and backupDir, and backups dir to backupDir. The backupDir generated by appending postfix `_bak` for dir. It does nothing if dir does not exist.

func Exit

func Exit(code int, msg string)

Exit the call exit system call with exit code and message

func ExpandDir

func ExpandDir(dir string) string

ExpandDir cleans the dir, and returns itself if it's absolute, otherwise prefix with the current/working directory.

func IsDirEmpty

func IsDirEmpty(name string) bool

IsDirEmpty returns true if a directory is empty.

func MkdirAll

func MkdirAll(path string) error

MkdirAll wraps os.MakeAll with fixed perm.

func NormalizeZapLogPath

func NormalizeZapLogPath(path string) string

NormalizeZapLogPath is a workaround for https://github.com/uber-go/zap/issues/621 the workaround is from https://github.com/ipfs/go-log/issues/73

func NotifySignal

func NotifySignal(c chan<- Signal, sig ...Signal) error

NotifySignal is identical to os/signal.Notify on Linux param is mapped to abstract Signal and nil is not allowed

func RaiseSignal

func RaiseSignal(pid int, sig Signal) error

RaiseSignal is identical to syscall.Kill on Linux param is mapped to abstract Signal

any chan passed to NotifySignal will receive the sig

func RemoveAll

func RemoveAll(path string) error

RemoveAll wraps os.RemoveAll.

func ValidateName

func ValidateName(name string) error

ValidateName validates the name.

Types

type Signal

type Signal string

Signal is cross-platform abstract type of os.Signal

const (
	// SignalInt represents quit in Easegress
	SignalInt Signal = "int"
	// SignalTerm represents force quit in Easegress
	SignalTerm Signal = "term"

	// SignalUsr2 represents reload signal in Easegress
	SignalUsr2 Signal = "usr2"
)

Jump to

Keyboard shortcuts

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