Documentation
¶
Overview ¶
Package utils provides some common utility methods
Index ¶
- func ByteCountIEC(b int64) string
- func ByteCountSI(b int64) string
- func CleanDirInput(dirInput string) string
- func CleanPath(p string) string
- func DecryptData(data string) (string, error)
- func EncryptData(data string) (string, error)
- func GenerateECDSAKeys(file string) error
- func GenerateRSAKeys(file string) error
- func GetDirsForSFTPPath(p string) []string
- func GetDurationAsString(d time.Duration) string
- func GetIPFromRemoteAddress(remoteAddress string) string
- func GetTimeAsMsSinceEpoch(t time.Time) int64
- func GetTimeFromMsecSinceEpoch(msec int64) time.Time
- func IsFileInputValid(fileInput string) bool
- func IsStringInSlice(obj string, list []string) bool
- func IsStringPrefixInSlice(obj string, list []string) bool
- func LoadTemplate(t *template.Template, err error) *template.Template
- func NilIfEmpty(s string) *string
- func RemoveDecryptionKey(encryptData string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteCountIEC ¶
ByteCountIEC returns humanized size in IEC (binary) format
func ByteCountSI ¶
ByteCountSI returns humanized size in SI (decimal) format
func CleanDirInput ¶
CleanDirInput sanitizes user input for directories. On Windows it removes any trailing `"`. We try to help windows users that set an invalid path such as "C:\ProgramData\SFTPGO\". This will only help if the invalid path is the last argument, for example in this command: sftpgo.exe serve -c "C:\ProgramData\SFTPGO\" -l "sftpgo.log" the -l flag will be ignored and the -c flag will get the value `C:\ProgramData\SFTPGO" -l sftpgo.log` since the backslash after SFTPGO escape the double quote. This is definitely a bad user input
func DecryptData ¶
DecryptData decrypts data encrypted using EncryptData
func EncryptData ¶
EncryptData encrypts data using the given key
func GenerateECDSAKeys ¶
GenerateECDSAKeys generate ecdsa private and public keys and write the private key to specified file and the public key to the specified file adding the .pub suffix
func GenerateRSAKeys ¶
GenerateRSAKeys generate rsa private and public keys and write the private key to specified file and the public key to the specified file adding the .pub suffix
func GetDirsForSFTPPath ¶
GetDirsForSFTPPath returns all the directory for the given path in reverse order for example if the path is: /1/2/3/4 it returns: [ "/1/2/3/4", "/1/2/3", "/1/2", "/1", "/" ]
func GetDurationAsString ¶
GetDurationAsString returns a string representation for a time.Duration
func GetIPFromRemoteAddress ¶
GetIPFromRemoteAddress returns the IP from the remote address. If the given remote address cannot be parsed it will be returned unchanged
func GetTimeAsMsSinceEpoch ¶
GetTimeAsMsSinceEpoch returns unix timestamp as milliseconds from a time struct
func GetTimeFromMsecSinceEpoch ¶
GetTimeFromMsecSinceEpoch return a time struct from a unix timestamp with millisecond precision
func IsFileInputValid ¶
IsFileInputValid returns true this is a valid file name. This method must be used before joining a file name, generally provided as user input, with a directory
func IsStringInSlice ¶
IsStringInSlice searches a string in a slice and returns true if the string is found
func IsStringPrefixInSlice ¶
IsStringPrefixInSlice searches a string prefix in a slice and returns true if a matching prefix is found
func LoadTemplate ¶
LoadTemplate wraps a call to a function returning (*Template, error) it is just like template.Must but it writes a log before exiting
func NilIfEmpty ¶
NilIfEmpty returns nil if the input string is empty
func RemoveDecryptionKey ¶
RemoveDecryptionKey returns encrypted data without the decryption key
Types ¶
This section is empty.