util

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathRoot           = "/"
	PathInit           = "/init"
	PathSearch         = "/search"
	PathOpensearch     = "/opensearch.xml"
	PathBlogs          = "/blogs"
	PathConsoleDist    = "/console/dist"
	PathAdmin          = "/admin"
	PathAPI            = "/api"
	PathFavicon        = "/favicon.ico"
	PathTheme          = "/theme"
	PathActivities     = "/activities"
	PathArchives       = "/archives"
	PathArticles       = "/articles"
	PathAuthors        = "/authors"
	PathCategories     = "/categories"
	PathTags           = "/tags"
	PathComments       = "/comments"
	PathAtom           = "/atom"
	PathRSS            = "/rss"
	PathSitemap        = "/sitemap.xml"
	PathUpload         = "/upload"
	PathFetchUpload    = "/fetch-upload"
	PathChangelogs     = "/changelogs"
	PathRobots         = "/robots.txt"
	PathAPIsSymArticle = "/apis/symphony/article"
	PathAPIsSymComment = "/apis/symphony/comment"
	PathPlatInfo       = "/plat/info"
	PathRegister       = "/register"
	PathLogin          = "/login"
)

Path prefixes.

View Source
const HacPaiURL = "https://hacpai.com"

HacPaiURL is the URL of HacPai community.

Variables

View Source
var File = myfile{}

File utilities.

View Source
var Zip = myzip{}

Zip utilities.

Functions

func CurrentMillisecond

func CurrentMillisecond() uint64

CurrentMillisecond returns the current time in millisecond.

func GetPage

func GetPage(c *gin.Context) int

GetPage returns paging parameter.

func GetRemoteAddr added in v1.1.0

func GetRemoteAddr(c *gin.Context) string

GetRemoteAddr returns remote address of the context.

func HacPaiAPI

func HacPaiAPI() gin.HandlerFunc

HacPaiAPI is a reverse proxy for https://hacpai.com.

func ImageSize

func ImageSize(imageURL string, width, height int) string

ImageSize returns image URL of Qiniu image processing style with the specified width and height.

func IsDomain

func IsDomain(s string) bool

IsDomain checks the specified string is domain name.

func IsIP

func IsIP(s string) bool

IsIP checks the specified string is IP.

func IsLetter

func IsLetter(r rune) bool

IsLetter checks the specified run is letter.

func IsNumOrLetter added in v1.4.0

func IsNumOrLetter(r rune) bool

IsNumOrLetter checks the specified rune is number or letter.

func IsReservedPath

func IsReservedPath(path string) bool

IsReservedPath checks the specified path is a reserved path or not.

func IsWindows

func IsWindows() bool

IsWindows determines whether current OS is Windows.

func LoadMarkdown added in v1.4.0

func LoadMarkdown()

LoadMarkdown loads markdown process engine.

func Pwd

func Pwd() string

Pwd gets the path of current working directory.

func RandAvatarData added in v1.8.0

func RandAvatarData() (ret []byte)

RandAvatarData returns random avatar image byte array data from Gravatar (http://www.gravatar.com). Sees https://github.com/b3log/pipe/issues/131 for more details.

func RandImage

func RandImage() string

RandImage returns an image URL randomly for article thumbnail. https://github.com/b3log/bing

func RandImages

func RandImages(n int) []string

RandImages returns random image URLs.

func RandInts

func RandInts(from, to, size int) []int

RandInts returns a random integer array with the specified from, to and size.

func RandString added in v1.8.0

func RandString(n int) string

RandString returns a fixed length random string.

func Recover

func Recover()

Recover recovers a panic.

func UserHome

func UserHome() (string, error)

UserHome returns the home directory for the executing user.

This uses an OS-specific method for discovering the home directory. An error is returned if a home directory cannot be detected.

Types

type MarkdownResult

type MarkdownResult struct {
	ContentHTML  string
	AbstractText string
	ThumbURL     string
}

MarkdownResult represents markdown result.

func Markdown

func Markdown(mdText string) *MarkdownResult

Markdown process the specified markdown text to HTML.

type Pagination

type Pagination struct {
	CurrentPageNum  int    `json:"currentPageNum"`
	PageSize        int    `json:"pageSize"`
	PageCount       int    `json:"pageCount"`
	WindowSize      int    `json:"windowSize"`
	RecordCount     int    `json:"recordCount"`
	PageNums        []int  `json:"pageNums"`
	NextPageNum     int    `json:"nextPageNum"`
	PreviousPageNum int    `json:"previousPageNum"`
	FirstPageNum    int    `josn:"firstPageNum"`
	LastPageNum     int    `json:"lastPageNum"`
	PageURL         string `json:"pageURL"`
}

Pagination represents pagination info.

func NewPagination

func NewPagination(currentPageNum, pageSize, windowSize, recordCount int) *Pagination

NewPagination creates a new pagination with the specified current page num, page size, window size and record count.

type Result

type Result struct {
	Code int         `json:"code"` // return code, 0 for succ
	Msg  string      `json:"msg"`  // message
	Data interface{} `json:"data"` // data object
}

Result represents HTTP response body.

func NewResult

func NewResult() *Result

NewResult creates a result with Code=0, Msg="", Data=nil.

type SessionData

type SessionData struct {
	UID     uint64 // user ID
	UName   string // username
	UB3Key  string // user B3 key
	URole   int    // user role
	UAvatar string // user avatar URL
	BID     uint64 // blog ID
	BURL    string // blog url
}

SessionData represents the session.

func GetSession

func GetSession(c *gin.Context) *SessionData

GetSession returns session of the specified context.

func (*SessionData) AvatarURLWithSize

func (sd *SessionData) AvatarURLWithSize(size int) string

AvatarURLWithSize returns avatar URL with the specified size.

func (*SessionData) Save

func (sd *SessionData) Save(c *gin.Context) error

Save saves the current session of the specified context.

type ZipFile

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

ZipFile represents a zip file.

func (*ZipFile) AddDirectory

func (z *ZipFile) AddDirectory(path, dirName string) error

AddDirectory adds a directory.

func (*ZipFile) AddDirectoryN

func (z *ZipFile) AddDirectoryN(path string, names ...string) error

AddDirectoryN adds directories.

func (*ZipFile) AddEntry

func (z *ZipFile) AddEntry(path, name string) error

AddEntry adds a entry.

func (*ZipFile) AddEntryN

func (z *ZipFile) AddEntryN(path string, names ...string) error

AddEntryN adds entries.

func (*ZipFile) Close

func (z *ZipFile) Close() error

Close closes the zip file writer.

Jump to

Keyboard shortcuts

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