base

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2014 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BindingRequireError         string = "Required"
	BindingAlphaDashError       string = "AlphaDash"
	BindingMinSizeError         string = "MinSize"
	BindingMaxSizeError         string = "MaxSize"
	BindingEmailError           string = "Email"
	BindingUrlError             string = "Url"
	BindingDeserializationError string = "DeserializationError"
	BindingIntegerTypeError     string = "IntegerTypeError"
	BindingBooleanTypeError     string = "BooleanTypeError"
	BindingFloatTypeError       string = "FloatTypeError"
)
View Source
const (
	TPL_CREATE_REPO    = `<a href="/user/%s">%s</a> created repository <a href="/%s">%s</a>`
	TPL_COMMIT_REPO    = `<a href="/user/%s">%s</a> pushed to <a href="/%s/src/%s">%s</a> at <a href="/%s">%s</a>%s`
	TPL_COMMIT_REPO_LI = `<div><img src="%s?s=16" alt="user-avatar"/> <a href="/%s/commit/%s" rel="nofollow">%s</a> %s</div>`
	TPL_CREATE_ISSUE   = `<a href="/user/%s">%s</a> opened issue <a href="/%s/issues/%s">%s#%s</a>
<div><img src="%s?s=16" alt="user-avatar"/> %s</div>`
	TPL_TRANSFER_REPO = `<a href="/user/%s">%s</a> transfered repository <code>%s</code> to <a href="/%s">%s</a>`
	TPL_PUSH_TAG      = `<a href="/user/%s">%s</a> pushed tag <a href="/%s/src/%s" rel="nofollow">%s</a> at <a href="/%s">%s</a>`
)
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 (
	AppVer      string
	AppName     string
	AppUrl      string
	OfflineMode bool
	ProdMode    bool
	Domain      string
	SecretKey   string
	RunUser     string

	RepoRootPath string
	ScriptType   string

	InstallLock bool

	LogInRememberDays  int
	CookieUserName     string
	CookieRememberName string

	Cfg          *goconfig.ConfigFile
	MailService  *Mailer
	OauthService *Oauther

	LogMode   string
	LogConfig string

	Cache        cache.Cache
	CacheAdapter string
	CacheConfig  string

	SessionProvider string
	SessionConfig   *session.Config
	SessionManager  *session.Manager

	PictureService string

	EnableRedis    bool
	EnableMemcache bool
)
View Source
var GoGetMetas = make(map[string]bool)
View Source
var (
	MentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`)
)
View Source
var Service struct {
	RegisterEmailConfirm bool
	DisableRegistration  bool
	RequireSignInView    bool
	EnableCacheAvatar    bool
	NotifyMail           bool
	ActiveCodeLives      int
	ResetPwdCodeLives    int
	LdapAuth             bool
}
View Source
var TemplateFuncs template.FuncMap = map[string]interface{}{
	"AppName": func() string {
		return AppName
	},
	"AppVer": func() string {
		return AppVer
	},
	"AppDomain": func() string {
		return Domain
	},
	"CdnMode": func() bool {
		return ProdMode && !OfflineMode
	},
	"LoadTimes": func(startTime time.Time) string {
		return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
	},
	"AvatarLink": AvatarLink,
	"str2html":   Str2html,
	"TimeSince":  TimeSince,
	"FileSize":   FileSize,
	"Subtract":   Subtract,
	"Add": func(a, b int) int {
		return a + b
	},
	"ActionIcon": ActionIcon,
	"ActionDesc": ActionDesc,
	"DateFormat": DateFormat,
	"List":       List,
	"Mail2Domain": func(mail string) string {
		if !strings.Contains(mail, "@") {
			return "try.gogits.org"
		}

		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 {
		return str[start : start+length]
	},
	"DiffTypeToStr":     DiffTypeToStr,
	"DiffLineTypeToStr": DiffLineTypeToStr,
	"ShortSha":          ShortSha,
	"Oauth2Icon":        Oauth2Icon,
}

Functions

func ActionDesc

func ActionDesc(act Actioner) string

ActionDesc accepts int that represents action operation type and returns the description.

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 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 ExecDir

func ExecDir() (string, error)

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 NewBaseServices added in v0.3.0

func NewBaseServices()

func NewConfigContext

func NewConfigContext()

func Oauth2Icon added in v0.3.0

func Oauth2Icon(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 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(then time.Time) string

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 ToStr

func ToStr(value interface{}, args ...int) (s string)

convert any type to string

func VerifyTimeLimitCode

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

verify time limit code

Types

type Actioner

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

type BindingErrors added in v0.3.0

type BindingErrors struct {
	Overall map[string]string `json:"overall"`
	Fields  map[string]string `json:"fields"`
}

Errors represents the contract of the response body when the binding step fails before getting to the application.

func (*BindingErrors) Combine added in v0.3.0

func (this *BindingErrors) Combine(other BindingErrors)

func (BindingErrors) Count added in v0.3.0

func (err BindingErrors) Count() int

Total errors is the sum of errors with the request overall and errors on individual fields.

type CustomRender

type CustomRender struct {
	gfm.Renderer
	// contains filtered or unexported fields
}
func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte, content []byte)

type Mailer

type Mailer struct {
	Name         string
	Host         string
	User, Passwd string
}

Mailer represents mail service.

type OauthInfo added in v0.3.0

type OauthInfo struct {
	ClientId, ClientSecret string
	Scopes                 string
	AuthUrl, TokenUrl      string
}

type Oauther added in v0.3.0

type Oauther struct {
	GitHub, Google, Tencent,
	Twitter, Weibo bool
	OauthInfos map[string]*OauthInfo
}

Oauther represents oauth service.

type PushCommit

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

type PushCommits

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

type StrTo

type StrTo string

func (StrTo) Exist

func (f StrTo) Exist() bool

func (StrTo) Int

func (f StrTo) Int() (int, error)

func (StrTo) Int64

func (f StrTo) Int64() (int64, error)

func (StrTo) String

func (f StrTo) String() string

type TmplData

type TmplData map[string]interface{}

Type TmplData represents data in the templates.

Jump to

Keyboard shortcuts

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