{"modulePath":"github.com/devfans/gogs","version":"v0.11.53","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package tool\n\n## Constants\n\n```go\nconst (\n\tByte  = 1\n\tKByte = Byte * 1024\n\tMByte = KByte * 1024\n\tGByte = MByte * 1024\n\tTByte = GByte * 1024\n\tPByte = TByte * 1024\n\tEByte = PByte * 1024\n)\n```\n\n```go\nconst (\n\tMinute = 60\n\tHour   = 60 * Minute\n\tDay    = 24 * Hour\n\tWeek   = 7 * Day\n\tMonth  = 30 * Day\n\tYear   = 12 * Month\n)\n```\nSeconds-based time units\n\n```go\nconst TIME_LIMIT_CODE_LENGTH = 12 + 6 + 40\n```\n\n## Functions\n\n```go\nfunc AppendAvatarSize(url string, size int) string\n```\nAppendAvatarSize appends avatar size query parameter to the URL in the correct format.\n\n```go\nfunc AvatarLink(email string) (url string)\n```\nAvatarLink returns relative avatar link to the site domain by given email, which includes app sub-url as prefix. However, it is possible to return full URL if user enables Gravatar-like service.\n\n```go\nfunc BasicAuthDecode(encoded string) (string, string, error)\n```\nBasicAuthDecode decodes username and password portions of HTTP Basic Authentication from encoded content.\n\n```go\nfunc BasicAuthEncode(username, password string) string\n```\nBasicAuthEncode encodes username and password in HTTP Basic Authentication format.\n\n```go\nfunc CreateTimeLimitCode(data string, minutes int, startInf interface{}) string\n```\nCreateTimeLimitCode generates a time limit code based on given input data. Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string\n\n```go\nfunc DetectEncoding(content []byte) (string, error)\n```\nDetectEncoding returns best guess of encoding of given content.\n\n```go\nfunc EllipsisString(str string, length int) string\n```\nEllipsisString returns a truncated short string, it appends '...' in the end of the length of string is too large.\n\n```go\nfunc FileSize(s int64) string\n```\nFileSize calculates the file size and generate user-friendly string.\n\n```go\nfunc HashEmail(email string) string\n```\nHashEmail hashes email address to MD5 string. [https://en.gravatar.com/site/implement/hash/](https://en.gravatar.com/site/implement/hash/)\n\n```go\nfunc Int64sToMap(ints []int64) map[int64]bool\n```\nInt64sToMap converts a slice of int64 to a int64 map.\n\n```go\nfunc Int64sToStrings(ints []int64) []string\n```\nInt64sToStrings converts a slice of int64 to a slice of string.\n\n```go\nfunc IsImageFile(data []byte) bool\n```\n\n```go\nfunc IsLetter(ch rune) bool\n```\nIsLetter reports whether the rune is a letter (category L). [https://github.com/golang/go/blob/master/src/go/scanner/scanner.go#L257](https://github.com/golang/go/blob/master/src/go/scanner/scanner.go#L257)\n\n```go\nfunc IsPDFFile(data []byte) bool\n```\n\n```go\nfunc IsTextFile(data []byte) bool\n```\nIsTextFile returns true if file content format is plain text or empty.\n\n```go\nfunc IsVideoFile(data []byte) bool\n```\n\n```go\nfunc MD5(str string) string\n```\nMD5 encodes string to MD5 hex value.\n\n```go\nfunc MD5Bytes(str string) []byte\n```\nMD5Bytes encodes string to MD5 bytes.\n\n```go\nfunc RandomString(n int) (string, error)\n```\nRandomString returns generated random string in given length of characters. It also returns possible error during generation.\n\n```go\nfunc RawTimeSince(t time.Time, lang string) string\n```\n\n```go\nfunc SHA1(str string) string\n```\nSHA1 encodes string to SHA1 hex value.\n\n```go\nfunc ShortSHA1(sha1 string) string\n```\nShortSHA1 truncates SHA1 string length to at most 10.\n\n```go\nfunc StringsToInt64s(strs []string) []int64\n```\nStringsToInt64s converts a slice of string to a slice of int64.\n\n```go\nfunc Subtract(left interface{}, right interface{}) interface{}\n```\nSubtract deals with subtraction of all types of number.\n\n```go\nfunc TimeSince(t time.Time, lang string) template.HTML\n```\nTimeSince calculates the time interval and generate user-friendly string.\n\n```go\nfunc TimeSincePro(then time.Time) string\n```\nTimeSincePro calculates the time interval and generate full user-friendly string.\n\n```go\nfunc TruncateString(str string, limit int) string\n```\nTruncateString returns a truncated string with given limit, it returns input string if length is not reached limit.\n\n```go\nfunc VerifyTimeLimitCode(data string, minutes int, code string) bool\n```\nverify time limit code\n\n","path":"github.com/devfans/gogs/pkg/tool","name":"tool","synopsis":"","isRedistributable":true}
