gitea: code.gitea.io/gitea/modules/base Index | Files

package base

import "code.gitea.io/gitea/modules/base"

Index

Package Files

base.go natural_sort.go tool.go

Constants

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

Seconds-based time units

const (
    Byte  = 1
    KByte = Byte * 1024
    MByte = KByte * 1024
    GByte = MByte * 1024
    TByte = GByte * 1024
    PByte = TByte * 1024
    EByte = PByte * 1024
)

Storage space size types

const DefaultAvatarSize = -1

DefaultAvatarSize is a sentinel value for the default avatar size, as determined by the avatar-hosting service.

const TimeLimitCodeLength = 12 + 6 + 40

TimeLimitCodeLength default value for time limit code

Variables

var UTF8BOM = []byte{'\xef', '\xbb', '\xbf'}

UTF8BOM is the utf-8 byte-order marker

func AvatarLink(email string) 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 Uses

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

BasicAuthDecode decode basic auth string

func BasicAuthEncode Uses

func BasicAuthEncode(username, password string) string

BasicAuthEncode encode basic auth string

func CreateTimeLimitCode Uses

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

CreateTimeLimitCode create a time limit code code format: 12 length date time string + 6 minutes string + 40 sha1 encoded string

func DefaultAvatarLink() string

DefaultAvatarLink the default avatar link

func DetectEncoding Uses

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

DetectEncoding detect the encoding of content

func EllipsisString Uses

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 EncodeMD5 Uses

func EncodeMD5(str string) string

EncodeMD5 encodes string to md5 hex value.

func EncodeSha1 Uses

func EncodeSha1(str string) string

EncodeSha1 string to sha1 hex value.

func EncodeSha256 Uses

func EncodeSha256(str string) string

EncodeSha256 string to sha1 hex value.

func EntryIcon Uses

func EntryIcon(entry *git.TreeEntry) string

EntryIcon returns the octicon class for displaying files/directories

func FileSize Uses

func FileSize(s int64) string

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

func GetRandomBytesAsBase64 Uses

func GetRandomBytesAsBase64(n int) string

GetRandomBytesAsBase64 generates a random base64 string from n bytes

func HashEmail Uses

func HashEmail(email string) string

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

func Int64sContains Uses

func Int64sContains(intsSlice []int64, a int64) bool

Int64sContains returns if a int64 in a slice of int64

func Int64sToMap Uses

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

Int64sToMap converts a slice of int64 to a int64 map.

func Int64sToStrings Uses

func Int64sToStrings(ints []int64) []string

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

func IsAudioFile Uses

func IsAudioFile(data []byte) bool

IsAudioFile detects if data is an video format

func IsImageFile Uses

func IsImageFile(data []byte) bool

IsImageFile detects if data is an image format

func IsLetter Uses

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 IsPDFFile Uses

func IsPDFFile(data []byte) bool

IsPDFFile detects if data is a pdf format

func IsTextFile Uses

func IsTextFile(data []byte) bool

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

func IsVideoFile Uses

func IsVideoFile(data []byte) bool

IsVideoFile detects if data is an video format

func MinutesToFriendly Uses

func MinutesToFriendly(minutes int, lang string) string

MinutesToFriendly returns a user friendly string with number of minutes converted to hours and minutes.

func NaturalSortLess Uses

func NaturalSortLess(s1, s2 string) bool

NaturalSortLess compares two strings so that they could be sorted in natural order

func RawTimeSince Uses

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

RawTimeSince retrieves i18n key of time since t

func RemoveBOMIfPresent Uses

func RemoveBOMIfPresent(content []byte) []byte

RemoveBOMIfPresent removes a UTF-8 BOM from a []byte

func SetupGiteaRoot Uses

func SetupGiteaRoot() string

SetupGiteaRoot Sets GITEA_ROOT if it is not already set and returns the value

func ShortSha Uses

func ShortSha(sha1 string) string

ShortSha is basically just truncating. It is DEPRECATED and will be removed in the future.

func SizedAvatarLink(email string, size int) string

SizedAvatarLink returns a sized link to the avatar for the given email address.

func StringsToInt64s Uses

func StringsToInt64s(strs []string) ([]int64, error)

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

func Subtract Uses

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

Subtract deals with subtraction of all types of number.

func TimeSince Uses

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

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

func TimeSincePro Uses

func TimeSincePro(then time.Time, lang string) string

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

func TimeSinceUnix Uses

func TimeSinceUnix(then util.TimeStamp, lang string) template.HTML

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

func TruncateString Uses

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 Uses

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

VerifyTimeLimitCode verify time limit code

type TplName Uses

type TplName string

TplName template relative path type

Package base imports 30 packages (graph) and is imported by 49 packages. Updated 2019-07-19. Refresh now. Tools for package owners.