Documentation ¶
Overview ¶
Package util defines variety of utilities.
Index ¶
- Constants
- Variables
- func CurrentMillisecond() uint64
- func GetPage(c *gin.Context) int
- func GetRemoteAddr(c *gin.Context) string
- func HacPaiAPI() gin.HandlerFunc
- func ImageSize(imageURL string, width, height int) string
- func IsDomain(s string) bool
- func IsIP(s string) bool
- func IsLetter(r rune) bool
- func IsNumOrLetter(r rune) bool
- func IsReservedPath(path string) bool
- func IsWindows() bool
- func LoadConf()
- func LoadMarkdown()
- func Pwd() string
- func RandImage() string
- func RandImages(n int) []string
- func RandInts(from, to, size int) []int
- func Recover()
- func UserHome() (string, error)
- type Configuration
- type MarkdownResult
- type Pagination
- type Result
- type SessionData
- type ZipFile
Constants ¶
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" PathAPIsSymArticles = "/apis/symphony/articles" PathAPIsSymComments = "/apis/symphony/comments" PathPlatInfo = "/plat/info" )
Path prefixes.
const HacPaiURL = "https://hacpai.com"
HacPaiURL is the URL of HacPai community.
const Version = "1.6.0"
Version of Pipe.
Variables ¶
var File = myfile{}
File utilities.
var Models = []interface{}{ &model.User{}, &model.Article{}, &model.Comment{}, &model.Navigation{}, &model.Tag{}, &model.Category{}, &model.Archive{}, &model.Setting{}, &model.Correlation{}, }
Models represents all models..
var UserAgent = "Mozilla/5.0 (compatible; Pipe" + Version + "; +" + HacPaiURL + ")"
UserAgent represents HTTP client user agent.
var ZeroPushTime, _ = time.Parse("2006-01-02 15:04:05", "2006-01-02 15:04:05")
ZeroPushTime represents zero push time.
var Zip = myzip{}
Zip utilities.
Functions ¶
func CurrentMillisecond ¶
func CurrentMillisecond() uint64
CurrentMillisecond returns the current time in millisecond.
func GetRemoteAddr ¶ added in v1.1.0
GetRemoteAddr returns remote address of the context.
func HacPaiAPI ¶
func HacPaiAPI() gin.HandlerFunc
HacPaiAPI is a reverse proxy for https://hacpai.com.
func ImageSize ¶
ImageSize returns image URL of Qiniu image processing style with the specified width and height.
func IsNumOrLetter ¶ added in v1.4.0
IsNumOrLetter checks the specified rune is number or letter.
func IsReservedPath ¶
IsReservedPath checks the specified path is a reserved path or not.
func LoadConf ¶
func LoadConf()
LoadConf loads the configurations. Command-line arguments will override configuration file.
func RandImage ¶
func RandImage() string
RandImage returns an image URL randomly for article thumbnail. https://github.com/b3log/bing
Types ¶
type Configuration ¶
type Configuration struct { Server string // server scheme, host and port StaticServer string // static resources server scheme, host and port StaticResourceVersion string // version of static resources LogLevel string // logging level: trace/debug/info/warn/error/fatal ShowSQL bool // whether print sql in log SessionSecret string // HTTP session secret SessionMaxAge int // HTTP session max age (in seciond) RuntimeMode string // runtime mode (dev/prod) SQLite string // SQLite database file path MySQL string // MySQL connection URL StaticRoot string // static resources file root path Port string // listen port AxiosBaseURL string // axio base URL MockServer string // mock server }
Configuration (pipe.json).
var Conf *Configuration
Conf of Pipe.
type MarkdownResult ¶
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.
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.
type ZipFile ¶
type ZipFile struct {
// contains filtered or unexported fields
}
ZipFile represents a zip file.
func (*ZipFile) AddDirectory ¶
AddDirectory adds a directory.
func (*ZipFile) AddDirectoryN ¶
AddDirectoryN adds directories.