base

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2014 License: MIT Imports: 27 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 DOC_URL = "http://gogs.io/docs"
View Source
const TimeLimitCodeLength = 12 + 6 + 40

Variables

View Source
var GoGetMetas = make(map[string]bool)
View Source
var (
	MentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`)
)
View Source
var TemplateFuncs template.FuncMap = map[string]interface{}{
	"GoVer": func() string {
		return strings.Title(runtime.Version())
	},
	"AppName": func() string {
		return setting.AppName
	},
	"AppSubUrl": func() string {
		return setting.AppSubUrl
	},
	"AppVer": func() string {
		return setting.AppVer
	},
	"AppDomain": func() string {
		return setting.Domain
	},
	"CdnMode": func() bool {
		return setting.ProdMode && !setting.OfflineMode
	},
	"LoadTimes": func(startTime time.Time) string {
		return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
	},
	"AvatarLink": AvatarLink,
	"str2html":   Str2html,
	"Str2html":   Str2html,
	"TimeSince":  TimeSince,
	"FileSize":   FileSize,
	"Subtract":   Subtract,
	"Add": func(a, b int) int {
		return a + b
	},
	"ActionIcon": ActionIcon,
	"DateFormat": DateFormat,
	"List":       List,
	"Mail2Domain": func(mail string) string {
		if !strings.Contains(mail, "@") {
			return "try.gogs.io"
		}

		suffix := strings.SplitN(mail, "@", 2)[1]
		domain, ok := mailDomains[suffix]
		if !ok {
			return "mail." + suffix
		}
		return domain
	},
	"SubStr": func(str string, start, length int) string {
		if len(str) == 0 {
			return ""
		}
		end := start + length
		if length == -1 {
			end = len(str)
		}
		if len(str) < end {
			return str
		}
		return str[start:end]
	},
	"DiffTypeToStr":         DiffTypeToStr,
	"DiffLineTypeToStr":     DiffLineTypeToStr,
	"ShortSha":              ShortSha,
	"Md5":                   EncodeMd5,
	"ActionContent2Commits": ActionContent2Commits,
	"Oauth2Icon":            Oauth2Icon,
	"Oauth2Name":            Oauth2Name,
	"ToUtf8":                ToUtf8,
	"EscapePound": func(str string) string {
		return strings.Replace(str, "#", "%23", -1)
	},
}

Functions

func ActionIcon

func ActionIcon(opType int) string

ActionIcon accepts a int that represents action operation type and returns a icon class name.

func AvatarLink(email string) string

AvatarLink returns avatar link by given e-mail.

func BasicAuthDecode added in v0.5.8

func BasicAuthDecode(encoded string) (user string, name string, err error)

func BasicAuthEncode added in v0.5.8

func BasicAuthEncode(username, password string) string

func CreateTimeLimitCode

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

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

func DateFormat

func DateFormat(t time.Time, format string) string

Date takes a PHP like date func to Go's time format.

func DateParse

func DateParse(dateString, format string) (time.Time, error)

Parse Date use PHP time format.

func DiffLineTypeToStr

func DiffLineTypeToStr(diffType int) string

func DiffTypeToStr

func DiffTypeToStr(diffType int) string

func EncodeMd5

func EncodeMd5(str string) string

Encode string to md5 hex value.

func EncodeSha1 added in v0.5.8

func EncodeSha1(str string) string

Encode string to sha1 hex value.

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 IsImageFile

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

func IsMarkdownFile

func IsMarkdownFile(name string) bool

func IsReadmeFile

func IsReadmeFile(name string) bool

func IsTextFile

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

func List

func List(l *list.List) chan interface{}

func Oauth2Icon added in v0.3.0

func Oauth2Icon(t int) string

func Oauth2Name added in v0.4.0

func Oauth2Name(t int) string

func PBKDF2 added in v0.3.0

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 Range

func Range(l int) []int

func RenderMarkdown

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

func RenderMarkdownString added in v0.3.0

func RenderMarkdownString(raw, urlPrefix string) string

func RenderRawMarkdown added in v0.4.0

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

func ShortSha

func ShortSha(sha1 string) string

func Str2html

func Str2html(raw string) template.HTML

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 ToUtf8 added in v0.5.2

func ToUtf8(content string) string

func ToUtf8WithErr added in v0.5.2

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

func VerifyTimeLimitCode

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

verify time limit code

func XSS added in v0.5.5

func XSS(in []byte) []byte

XSS goes through all the XSS filters to make user input content as safe as possible.

func XSSString added in v0.5.5

func XSSString(in string) string

Types

type Actioner

type Actioner interface {
	GetOpType() int
	GetActUserName() string
	GetActEmail() string
	GetRepoUserName() string
	GetRepoName() string
	GetBranch() string
	GetContent() string
}

type ApiJsonErr added in v0.4.0

type ApiJsonErr struct {
	Message string `json:"message"`
	DocUrl  string `json:"url"`
}

type CustomRender

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

func (*CustomRender) Image added in v0.5.8

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 PushCommit

type PushCommit struct {
	Sha1        string
	Message     string
	AuthorEmail string
	AuthorName  string
}

type PushCommits

type PushCommits struct {
	Len        int
	Commits    []*PushCommit
	CompareUrl string
}

func ActionContent2Commits added in v0.5.0

func ActionContent2Commits(act Actioner) *PushCommits

type TplName added in v0.5.0

type TplName string

Jump to

Keyboard shortcuts

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