base

package
v0.0.0-...-943e509 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: MIT Imports: 25 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 (
	Byte  = 1
	KByte = Byte * 1024
	MByte = KByte * 1024
	GByte = MByte * 1024
	TByte = GByte * 1024
	PByte = TByte * 1024
	EByte = PByte * 1024
)
View Source
const TimeLimitCodeLength = 12 + 6 + 40

Variables

View Source
var GoGetMetas = make(map[string]bool)
View Source
var (
	MentionPattern = regexp.MustCompile(`(\s|^)@[0-9a-zA-Z_\.]+`)
)
View Source
var Sanitizer = bluemonday.UGCPolicy().AllowAttrs("class", "data-original", "rel", "src").Matching(regexp.MustCompile(`[\p{L}\p{N}\s\-_',:\[\]!\./\\\(\)&]*`)).OnElements("code")

Functions

func BasicAuthDecode

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

func BasicAuthEncode

func BasicAuthEncode(username, password string) string

func EncodeMD5

func EncodeMD5(str string) string

EncodeMD5 encodes string to md5 hex value.

func EncodeSha1

func EncodeSha1(str string) string

Encode string to sha1 hex value.

func ExecPath

func ExecPath() (string, error)

ExecPath returns the executable path.

func FileSize

func FileSize(s int64) string

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

func GetRandomString

func GetRandomString(n int, alphabets ...byte) string

GetRandomString generate random string by specify chars.

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) (string, bool)

func IsMarkdownFile

func IsMarkdownFile(name string) bool

func IsReadmeFile

func IsReadmeFile(name string) bool

IsReadmeFile returns true if given file name suppose to be a README file.

func IsTextFile

func IsTextFile(data []byte) (string, bool)

func PBKDF2

func PBKDF2(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte

http://code.google.com/p/go/source/browse/pbkdf2/pbkdf2.go?repo=crypto

func PostProcessMarkdown

func PostProcessMarkdown(rawHtml []byte, urlPrefix string, metas map[string]string) []byte

PostProcessMarkdown treats different types of HTML differently, and only renders special links for plain text blocks.

func PreProcessMarkdown

func PreProcessMarkdown(rawHTML []byte, urlPrefix string) []byte

PreProcessMarkdown renders full links of commits, issues and pulls to shorter version.

func RawTimeSince

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

func RenderIssueIndexPattern

func RenderIssueIndexPattern(rawBytes []byte, urlPrefix string, metas map[string]string) []byte

func RenderMarkdown

func RenderMarkdown(rawBytes []byte, urlPrefix string, metas map[string]string) []byte

func RenderMarkdownString

func RenderMarkdownString(raw string) string

func RenderRawMarkdown

func RenderRawMarkdown(body []byte, urlPrefix string) []byte

func RenderSha1CurrentPattern

func RenderSha1CurrentPattern(rawBytes []byte, urlPrefix string) []byte

func ShortSha

func ShortSha(sha1 string) string

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.

Types

type CustomRender

type CustomRender struct {
	blackfriday.Renderer
	// contains filtered or unexported fields
}

func (*CustomRender) Image

func (options *CustomRender) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte)
func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte, content []byte)

type TplName

type TplName string

Jump to

Keyboard shortcuts

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