helper

package
v0.0.0-...-643e065 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrI18nUnknownExt = errors.New("unknown i18n ext")
)

Functions

func Gravatar

func Gravatar(email string, size int) string

Gravatar convert email to gravatar image path

func I18nDataFromINI

func I18nDataFromINI(data []byte) (map[string]map[string]string, error)

I18nDataFromINI parse ini data to map

func I18nDataFromTOML

func I18nDataFromTOML(data []byte) (map[string]map[string]string, error)

I18nDataFromTOML parse toml data to map

func LangCode

func LangCode(lang string) []string

LangCode returns correct language code possibly en-US -> [en-US,en-us,en]

func LogfmtFormat

func LogfmtFormat() log15.Format

LogfmtFormat format logs as fmt.Sprintf Example:

Debug("Debug|%s|%d","a",1)

func Markdown

func Markdown(raw []byte) []byte

Markdown converts markdown bytes to html bytes

func Md5

func Md5(str string) string

Md5 generate md5 hash from string

func Md5File

func Md5File(file string) (string, error)

Md5File generate file hash

Types

type I18n

type I18n struct {
	Lang string // language string
	// contains filtered or unexported fields
}

I18n object

func NewI18n

func NewI18n(lang string, data []byte, ext string) (*I18n, error)

NewI18n reads toml bytes

func NewI18nEmpty

func NewI18nEmpty() *I18n

NewI18nEmpty creates new empty i18n object, it will keep i18 tool working, but no translated value

func (*I18n) Tr

func (i *I18n) Tr(str string) string

Tr converts string

func (*I18n) Trf

func (i *I18n) Trf(str string, values ...interface{}) string

Trf converts string with arguments

func (*I18n) Trim

func (i *I18n) Trim(str string) string

Trim trims string with lang prefix

type Pager

type Pager struct {
	Begin   int
	End     int
	Prev    int
	Next    int
	Current int
	Pages   int
	All     int
	// contains filtered or unexported fields
}

Pager contains pagination data when on a page number

func (*Pager) NextURL

func (pg *Pager) NextURL() string

NextURL returns next url

func (*Pager) PageItems

func (pg *Pager) PageItems() []*PagerItem

PageItems returns each page item in this pager

func (*Pager) PrevURL

func (pg *Pager) PrevURL() string

PrevURL returns prev url

func (*Pager) SetLayout

func (pg *Pager) SetLayout(layout string)

SetLayout sets pager layout string, use to print url

func (*Pager) URL

func (pg *Pager) URL() string

URL returns page current url

type PagerCursor

type PagerCursor struct {
	// contains filtered or unexported fields
}

PagerCursor creates Pager with each page number

func NewPagerCursor

func NewPagerCursor(size, all int) *PagerCursor

NewPagerCursor with size and all count

func (*PagerCursor) Page

func (pg *PagerCursor) Page(i int) *Pager

Page creates Pager on a page number

type PagerItem

type PagerItem struct {
	Page int
	Link string
}

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker is a worker pool for function

func NewWorker

func NewWorker(size int) *Worker

NewWorker creates new Worker with size. If size is 0, use runtime.NumCPU()

func (*Worker) AddFunc

func (w *Worker) AddFunc(fn WorkerFunc)

AddFunc adds WorkerFunc

func (*Worker) Errors

func (w *Worker) Errors() []error

Errors returns errors when running WorkerFunc

func (*Worker) RunOnce

func (w *Worker) RunOnce()

RunOnce runs WorkerFunc and waits all goroutine end

type WorkerFunc

type WorkerFunc func() error

WorkerFunc is handler in Worker

Jump to

Keyboard shortcuts

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