Documentation ¶
Index ¶
- Variables
- func AESGCMDecrypt(key, ciphertext []byte) ([]byte, error)
- func AESGCMEncrypt(key, plaintext []byte) ([]byte, error)
- func ApplyUmask(f string, newMode os.FileMode) error
- func CommonSkip(name string) bool
- func CryptoRandomBytes(length int64) ([]byte, error)
- func CryptoRandomInt(limit int64) (int64, error)
- func CryptoRandomString(length int64) (string, error)
- func Dedent(s string) string
- func EnsureAbsolutePath(path, absoluteBase string) string
- func ExistsInSlice(target string, slice []string) bool
- func FileURLToPath(u *url.URL) (string, error)
- func GetDirectorySize(path string) (int64, error)
- func HomeDir() (home string, err error)
- func IsDir(dir string) (bool, error)
- func IsEmptyString(s string) bool
- func IsEqualSlice(target, source []string) bool
- func IsExist(path string) (bool, error)
- func IsFile(filePath string) (bool, error)
- func IsInt64InSlice(target int64, slice []int64) bool
- func IsSliceInt64Eq(a, b []int64) bool
- func IsStringInSlice(target string, slice []string, insensitive ...bool) bool
- func Max(a, b int) int
- func MergeInto(dict map[string]interface{}, values ...interface{}) (map[string]interface{}, error)
- func Min(a, b int) int
- func NormalizeEOL(input []byte) []byte
- func NumberIntoInt64(number interface{}) int64
- func PaginateSlice(list interface{}, page, pageSize int) interface{}
- func PathEscapeSegments(path string) string
- func ReadAtMost(r io.Reader, buf []byte) (n int, err error)
- func Remove(name string) error
- func RemoveAll(name string) error
- func RemoveIDFromList(list []int64, id int64) ([]int64, bool)
- func Rename(oldpath, newpath string) error
- func SanitizeCredentialURLs(s string) string
- func SanitizeErrorCredentialURLs(err error) error
- func SecToTime(duration int64) string
- func ShellEscape(toEscape string) string
- func SplitStringAtByteN(input string, n int) (left, right string)
- func SplitStringAtRuneN(input string, n int) (left, right string)
- func StatDir(rootPath string, includeDir ...bool) ([]string, error)
- func StopTimer(t *time.Timer) bool
- func ToSnakeCase(input string) string
- func ToTitleCase(s string) string
- func ToUpperASCII(s string) string
- func URLJoin(base string, elems ...string) string
- type Int64Slice
- type OptionalBool
- type Set
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidArgument = errors.New("invalid argument") ErrPermissionDenied = errors.New("permission denied") ErrAlreadyExist = errors.New("resource already exists") ErrNotExist = errors.New("resource does not exist") )
Common Errors forming the base of our error system
Many Errors returned by Gitea can be tested against these errors using errors.Is.
Functions ¶
func AESGCMDecrypt ¶
AESGCMDecrypt (from legacy package): decrypts ciphertext with the given key using AES in GCM mode. should be replaced.
func AESGCMEncrypt ¶
AESGCMEncrypt (from legacy package): encrypts plaintext with the given key using AES in GCM mode. should be replaced.
func CommonSkip ¶
CommonSkip will check a provided name to see if it represents file or directory that should not be watched
func CryptoRandomBytes ¶
CryptoRandomBytes generates `length` crypto bytes This differs from CryptoRandomString, as each byte in CryptoRandomString is generated by [0,61] range This function generates totally random bytes, each byte is generated by [0,255] range
func CryptoRandomInt ¶
CryptoRandomInt returns a crypto random integer between 0 and limit, inclusive
func CryptoRandomString ¶
CryptoRandomString generates a crypto random alphanumerical string, each byte is generated by [0,61] range
func Dedent ¶
Dedent removes common indentation of a multi-line string along with whitespace around it Based on https://github.com/lithammer/dedent
func EnsureAbsolutePath ¶
EnsureAbsolutePath ensure that a path is absolute, making it relative to absoluteBase if necessary
func ExistsInSlice ¶
ExistsInSlice returns true if string exists in slice.
func FileURLToPath ¶
FileURLToPath extracts the path information from a file://... url.
func GetDirectorySize ¶
GetDirectorySize returns the disk consumption for a given path
func HomeDir ¶
HomeDir returns path of '~'(in Linux) on Windows, it returns error when the variable does not exist.
func IsDir ¶
IsDir returns true if given path is a directory, or returns false when it's a file or does not exist.
func IsEmptyString ¶
IsEmptyString checks if the provided string is empty
func IsEqualSlice ¶
IsEqualSlice returns true if slices are equal.
func IsExist ¶
IsExist checks whether a file or directory exists. It returns false when the file or directory does not exist.
func IsFile ¶
IsFile returns true if given path is a file, or returns false when it's a directory or does not exist.
func IsInt64InSlice ¶
IsInt64InSlice sequential searches if int64 exists in slice.
func IsSliceInt64Eq ¶
IsSliceInt64Eq returns if the two slice has the same elements but different sequences.
func IsStringInSlice ¶
IsStringInSlice sequential searches if string exists in slice.
func NormalizeEOL ¶
NormalizeEOL will convert Windows (CRLF) and Mac (CR) EOLs to UNIX (LF)
func NumberIntoInt64 ¶
func NumberIntoInt64(number interface{}) int64
NumberIntoInt64 transform a given int into int64.
func PaginateSlice ¶
func PaginateSlice(list interface{}, page, pageSize int) interface{}
PaginateSlice cut a slice as per pagination options if page = 0 it do not paginate
func PathEscapeSegments ¶
PathEscapeSegments escapes segments of a path while not escaping forward slash
func ReadAtMost ¶
ReadAtMost reads at most len(buf) bytes from r into buf. It returns the number of bytes copied. n is only less than len(buf) if r provides fewer bytes. If EOF occurs while reading, err will be nil.
func RemoveIDFromList ¶
RemoveIDFromList removes the given ID from the slice, if found. It does not preserve order, and assumes the ID is unique.
func SanitizeCredentialURLs ¶
SanitizeCredentialURLs remove all credentials in URLs (starting with "scheme://") for the input string: "https://user:pass@domain.com" => "https://sanitized-credential@domain.com"
func SanitizeErrorCredentialURLs ¶
SanitizeErrorCredentialURLs wraps the error and make sure the returned error message doesn't contain sensitive credentials in URLs
func SecToTime ¶
SecToTime converts an amount of seconds to a human-readable string. E.g. 66s -> 1 minute 6 seconds 52410s -> 14 hours 33 minutes 563418 -> 6 days 12 hours 1563418 -> 2 weeks 4 days 3937125s -> 1 month 2 weeks 45677465s -> 1 year 6 months
func ShellEscape ¶
ShellEscape will escape the provided string. We can't just use go-shellquote here because our preferences for escaping differ from those in that we want:
* If the string doesn't require any escaping just leave it as it is. * If the string requires any escaping prefer double quote escaping * If we have ! or newlines then we need to use single quote escaping
func SplitStringAtByteN ¶
SplitStringAtByteN splits a string at byte n accounting for rune boundaries. (Combining characters are not accounted for.)
func SplitStringAtRuneN ¶
SplitStringAtRuneN splits a string at rune n accounting for rune boundaries. (Combining characters are not accounted for.)
func StatDir ¶
StatDir gathers information of given directory by depth-first. It returns slice of file list and includes subdirectories if enabled; it returns error and nil slice when error occurs in underlying functions, or given path is not a directory or does not exist.
Slice does not include given path itself. If subdirectories is enabled, they will have suffix '/'.
func ToSnakeCase ¶
ToSnakeCase convert the input string to snake_case format.
Some samples.
"FirstName" => "first_name" "HTTPServer" => "http_server" "NoHTTPS" => "no_https" "GO_PATH" => "go_path" "GO PATH" => "go_path" // space is converted to underscore. "GO-PATH" => "go_path" // hyphen is converted to underscore.
func ToTitleCase ¶
ToTitleCase returns s with all english words capitalized
func ToUpperASCII ¶
ToUpperASCII returns s with all ASCII letters mapped to their upper case.
Types ¶
type Int64Slice ¶
type Int64Slice []int64
Int64Slice attaches the methods of Interface to []int64, sorting in increasing order.
func (Int64Slice) Len ¶
func (p Int64Slice) Len() int
func (Int64Slice) Less ¶
func (p Int64Slice) Less(i, j int) bool
func (Int64Slice) Swap ¶
func (p Int64Slice) Swap(i, j int)
type OptionalBool ¶
type OptionalBool byte
OptionalBool a boolean that can be "null"
const ( // OptionalBoolNone a "null" boolean value OptionalBoolNone OptionalBool = iota // OptionalBoolTrue a "true" boolean value OptionalBoolTrue // OptionalBoolFalse a "false" boolean value OptionalBoolFalse )
func OptionalBoolOf ¶
func OptionalBoolOf(b bool) OptionalBool
OptionalBoolOf get the corresponding OptionalBool of a bool
func OptionalBoolParse ¶
func OptionalBoolParse(s string) OptionalBool
OptionalBoolParse get the corresponding OptionalBool of a string using strconv.ParseBool
func (OptionalBool) IsFalse ¶
func (o OptionalBool) IsFalse() bool
IsFalse return true if equal to OptionalBoolFalse
func (OptionalBool) IsNone ¶
func (o OptionalBool) IsNone() bool
IsNone return true if equal to OptionalBoolNone
func (OptionalBool) IsTrue ¶
func (o OptionalBool) IsTrue() bool
IsTrue return true if equal to OptionalBoolTrue
type Set ¶ added in v0.3.0
type Set[T comparable] map[T]struct{}
func SetOf ¶ added in v0.3.0
func SetOf[T comparable](values ...T) Set[T]
SetOf creates a set and adds the specified elements to it.
func (Set[T]) Add ¶ added in v0.3.0
Add adds the specified element to a set. Returns true if the element is added; false if the element is already present.
func (Set[T]) AddMultiple ¶ added in v0.3.0
func (s Set[T]) AddMultiple(values ...T)
AddMultiple adds the specified elements to a set.
func (Set[T]) Contains ¶ added in v0.3.0
Contains determines whether a set contains the specified element. Returns true if the set contains the specified element; otherwise, false.