tool

package
v0.0.0-...-2ad639e Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Minute = 60
	Hour   = 60 * Minute
	Day    = 24 * Hour
	Week   = 7 * Day
	Month  = 30 * Day
	Year   = 12 * Month
)

Seconds-based time units

View Source
const TIME_LIMIT_CODE_LENGTH = 12 + 6 + 40

Variables

This section is empty.

Functions

func AppendAvatarSize

func AppendAvatarSize(url string, size int) string

AppendAvatarSize appends avatar size query parameter to the URL in the correct format.

func AvatarLink(email string) (url string)

AvatarLink 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.

func BasicAuthDecode

func BasicAuthDecode(encoded string) (string, string, error)

BasicAuthDecode decodes username and password portions of HTTP Basic Authentication from encoded content.

func CreateTimeLimitCode

func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string

CreateTimeLimitCode generates a time limit code based on given input data. Format: 12 length date time string + 6 minutes string + 40 sha1 encoded string

func DetectEncoding

func DetectEncoding(content []byte) (string, error)

DetectEncoding returns best guess of encoding of given content.

func EllipsisString

func EllipsisString(str string, length int) string

EllipsisString returns a truncated short string, it appends '...' in the end of the length of string is too large.

func FileSize

func FileSize(s int64) string

FileSize calculates the file size and generate user-friendly string.

func HashEmail

func HashEmail(email string) string

HashEmail hashes email address to MD5 string. https://en.gravatar.com/site/implement/hash/

func Int64sToMap

func Int64sToMap(ints []int64) map[int64]bool

Int64sToMap converts a slice of int64 to a int64 map.

func Int64sToStrings

func Int64sToStrings(ints []int64) []string

Int64sToStrings converts a slice of int64 to a slice of string.

func IsImageFile

func IsImageFile(data []byte) bool

func IsLetter

func IsLetter(ch rune) bool

IsLetter reports whether the rune is a letter (category L). https://github.com/golang/go/blob/master/src/go/scanner/scanner.go#L257

func IsMaliciousPath

func IsMaliciousPath(path string) bool

IsMaliciousPath returns true if given path is an absolute path or contains malicious content which has potential to traverse upper level directories.

func IsPDFFile

func IsPDFFile(data []byte) bool

func IsSameSiteURLPath

func IsSameSiteURLPath(url string) bool

IsSameSiteURLPath returns true if the URL path belongs to the same site, false otherwise. False: //url, http://url, /\url True: /url

func IsTextFile

func IsTextFile(data []byte) bool

IsTextFile returns true if file content format is plain text or empty.

func IsVideoFile

func IsVideoFile(data []byte) bool

func RawTimeSince

func RawTimeSince(t time.Time, lang string) string

func ShortSHA1

func ShortSHA1(sha1 string) string

ShortSHA1 truncates SHA1 string length to at most 10.

func StringsToInt64s

func StringsToInt64s(strs []string) []int64

StringsToInt64s converts a slice of string to a slice of int64.

func Subtract

func Subtract(left interface{}, right interface{}) interface{}

Subtract deals with subtraction of all types of number.

func TimeSince

func TimeSince(t time.Time, lang string) template.HTML

TimeSince calculates the time interval and generate user-friendly string.

func TimeSincePro

func TimeSincePro(then time.Time) string

TimeSincePro calculates the time interval and generate full user-friendly string.

func TruncateString

func TruncateString(str string, limit int) string

TruncateString returns a truncated string with given limit, it returns input string if length is not reached limit.

func VerifyTimeLimitCode

func VerifyTimeLimitCode(data string, minutes int, code string) bool

verify time limit code

Types

This section is empty.

Jump to

Keyboard shortcuts

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