utils

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package utils provides common utilities for the tryssh application.

Index

Constants

View Source
const ConfigFileMode = 0600

ConfigFileMode is the default file permission used for config files.

Variables

This section is empty.

Functions

func CheckFileIsExist

func CheckFileIsExist(filename string) bool

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

func CreateFile(filePath string, perm fs.FileMode) error

CreateFile creates an empty file with the specified permissions atomically.

func Decrypt added in v0.4.0

func Decrypt(encrypted string, key []byte) (string, error)

Decrypt decrypts a prefixed base64 string back to plaintext.

func Encrypt added in v0.4.0

func Encrypt(plaintext string, key []byte) (string, error)

Encrypt encrypts plaintext and returns a prefixed base64 string.

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

func FileYamlMarshalAndWrite(path string, conf interface{}) error

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

func GetCachedMasterKey() ([]byte, error)

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

func GetMasterKey() ([]byte, error)

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

func IsEncrypted(s string) bool

IsEncrypted checks if a value has the encrypted prefix.

func MaskSecret added in v0.4.0

func MaskSecret(s string) string

MaskSecret masks a secret string, returning a fixed-length indicator.

func ReadFile

func ReadFile(filePath string) ([]byte, bool)

ReadFile reads the entire file and returns its contents.

func RemoveDuplicate

func RemoveDuplicate(s []string) []string

RemoveDuplicate removes duplicate strings from the slice, preserving order.

func SetLogLevel added in v0.4.0

func SetLogLevel(level logrus.Level)

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

func UpdateFile(filePath string, fileContent []byte, perm fs.FileMode) error

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.

func Warnf added in v0.4.0

func Warnf(format string, args ...interface{})

Warnf logs formatted warning messages at the Warn level.

func Warnln added in v0.4.0

func Warnln(args ...interface{})

Warnln logs warning messages with a newline at the Warn level.

Types

This section is empty.

Jump to

Keyboard shortcuts

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