utils

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: GPL-3.0 Imports: 24 Imported by: 1

Documentation

Overview

Package utils provides some common utility methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCountIEC

func ByteCountIEC(b int64) string

ByteCountIEC returns humanized size in IEC (binary) format

func ByteCountSI

func ByteCountSI(b int64) string

ByteCountSI returns humanized size in SI (decimal) format

func CleanDirInput

func CleanDirInput(dirInput string) string

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 CleanPath added in v1.1.0

func CleanPath(p string) string

CleanPath returns a clean POSIX (/) absolute path to work with

func DecryptData

func DecryptData(data string) (string, error)

DecryptData decrypts data encrypted using EncryptData

func EncryptData

func EncryptData(data string) (string, error)

EncryptData encrypts data using the given key

func GenerateECDSAKeys

func GenerateECDSAKeys(file string) error

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 GenerateEd25519Keys added in v1.2.0

func GenerateEd25519Keys(file string) error

GenerateEd25519Keys generate ed25519 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

func GenerateRSAKeys(file string) error

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

func GetDirsForSFTPPath(p string) []string

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

func GetDurationAsString(d time.Duration) string

GetDurationAsString returns a string representation for a time.Duration

func GetIPFromRemoteAddress

func GetIPFromRemoteAddress(remoteAddress string) string

GetIPFromRemoteAddress returns the IP from the remote address. If the given remote address cannot be parsed it will be returned unchanged

func GetTimeAsMsSinceEpoch

func GetTimeAsMsSinceEpoch(t time.Time) int64

GetTimeAsMsSinceEpoch returns unix timestamp as milliseconds from a time struct

func GetTimeFromMsecSinceEpoch

func GetTimeFromMsecSinceEpoch(msec int64) time.Time

GetTimeFromMsecSinceEpoch return a time struct from a unix timestamp with millisecond precision

func IsFileInputValid

func IsFileInputValid(fileInput string) bool

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

func IsStringInSlice(obj string, list []string) bool

IsStringInSlice searches a string in a slice and returns true if the string is found

func IsStringPrefixInSlice

func IsStringPrefixInSlice(obj string, list []string) bool

IsStringPrefixInSlice searches a string prefix in a slice and returns true if a matching prefix is found

func LoadTemplate

func LoadTemplate(t *template.Template, err error) *template.Template

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

func NilIfEmpty(s string) *string

NilIfEmpty returns nil if the input string is empty

func RemoveDecryptionKey

func RemoveDecryptionKey(encryptData string) string

RemoveDecryptionKey returns encrypted data without the decryption key

func RemoveDuplicates added in v1.2.2

func RemoveDuplicates(obj []string) []string

RemoveDuplicates returns a new slice removing any duplicate element from the initial one

Types

This section is empty.

Jump to

Keyboard shortcuts

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