Documentation
¶
Overview ¶
Package utils provides common utilities for the tryssh application.
Index ¶
- Constants
- func CheckFileIsExist(filename string) bool
- func ClearMasterKey()
- func CreateFile(filePath string, perm fs.FileMode) error
- func Decrypt(encrypted string, key []byte) (string, error)
- func Encrypt(plaintext string, key []byte) (string, error)
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func FileYamlMarshalAndWrite(path string, conf interface{}) error
- func GetCachedMasterKey() ([]byte, error)
- func GetMasterKey() ([]byte, error)
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func IsEncrypted(s string) bool
- func MaskSecret(s string) string
- func ReadFile(filePath string) ([]byte, bool)
- func RemoveDuplicate(s []string) []string
- func SetLogLevel(level logrus.Level)
- func ToInterfaceSlice[T any](s []T) []interface{}
- func UpdateFile(filePath string, fileContent []byte, perm fs.FileMode) error
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warnln(args ...interface{})
Constants ¶
const ConfigFileMode = 0600
ConfigFileMode is the default file permission used for config files.
Variables ¶
This section is empty.
Functions ¶
func CheckFileIsExist ¶
CheckFileIsExist returns true if the file exists (including when unreadable due to permissions).
func ClearMasterKey ¶ added in v0.4.0
func ClearMasterKey()
ClearMasterKey removes the cached master key from memory.
func CreateFile ¶
CreateFile creates an empty file with the specified permissions atomically.
func Error ¶ added in v0.4.0
func Error(args ...interface{})
Error logs error messages at the Error level.
func Errorf ¶ added in v0.4.0
func Errorf(format string, args ...interface{})
Errorf logs formatted error messages at the Error level.
func Errorln ¶ added in v0.4.0
func Errorln(args ...interface{})
Errorln logs error messages with a newline at the Error level.
func Fatal ¶ added in v0.4.0
func Fatal(args ...interface{})
Fatal logs messages at the Fatal level and exits.
func Fatalf ¶ added in v0.4.0
func Fatalf(format string, args ...interface{})
Fatalf logs formatted messages at the Fatal level and exits.
func Fatalln ¶ added in v0.4.0
func Fatalln(args ...interface{})
Fatalln logs messages with a newline at the Fatal level and exits.
func FileYamlMarshalAndWrite ¶
FileYamlMarshalAndWrite marshals the given value to YAML and writes it atomically to the specified path, creating parent directories as needed.
func GetCachedMasterKey ¶ added in v0.4.1
GetCachedMasterKey returns the master key only if already cached or available via the environment variable, without prompting interactively.
func GetMasterKey ¶ added in v0.4.0
GetMasterKey returns the cached master key, prompting for it if necessary.
func Info ¶ added in v0.4.0
func Info(args ...interface{})
Info logs informational messages at the Info level.
func Infof ¶ added in v0.4.0
func Infof(format string, args ...interface{})
Infof logs formatted informational messages at the Info level.
func Infoln ¶ added in v0.4.0
func Infoln(args ...interface{})
Infoln logs informational messages with a newline at the Info level.
func IsEncrypted ¶ added in v0.4.0
IsEncrypted checks if a value has the encrypted prefix.
func MaskSecret ¶ added in v0.4.0
MaskSecret masks a secret string, returning a fixed-length indicator.
func RemoveDuplicate ¶
RemoveDuplicate removes duplicate strings from the slice, preserving order.
func SetLogLevel ¶ added in v0.4.0
SetLogLevel changes the global log level.
func ToInterfaceSlice ¶ added in v0.4.0
func ToInterfaceSlice[T any](s []T) []interface{}
ToInterfaceSlice converts a typed slice to []interface{} using generics.
func UpdateFile ¶
UpdateFile writes the given content to the file with the specified permissions atomically using a temporary file and rename to prevent corruption on crash.
func Warn ¶ added in v0.4.0
func Warn(args ...interface{})
Warn logs warning messages at the Warn level.
Types ¶
This section is empty.