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 IsReservedPath(path string) bool
- func IsWindows() bool
- func LoadConf()
- 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 ¶
View Source
const ( PathRoot = "/" PathInit = "/init" PathSearch = "/search" 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" PathUpload = "/upload" PathFetchUpload = "/fetch-upload" PathChangelogs = "/changelogs" PathRobots = "/robots.txt" )
Path prefixes.
View Source
const HacPaiURL = "https://hacpai.com"
View Source
const Version = "1.2.0"
Pipe version.
Variables ¶
View Source
var File = myfile{}
File utilities.
View Source
var Models = []interface{}{ &model.User{}, &model.Article{}, &model.Comment{}, &model.Navigation{}, &model.Tag{}, &model.Category{}, &model.Archive{}, &model.Setting{}, &model.Correlation{}, }
Database models.
View Source
var UserAgent = "Mozilla/5.0 (compatible; Pipe" + Version + "; +" + HacPaiURL + ")"
HTTP client user agent.
View Source
var ZeroPushTime, _ = time.Parse("2006-01-02 15:04:05", "2006-01-02 15:04:05")
Zero push time.
View Source
var Zip = myzip{}
Zip utilities.
Functions ¶
func CurrentMillisecond ¶
func CurrentMillisecond() uint64
func GetRemoteAddr ¶ added in v1.1.0
func HacPaiAPI ¶
func HacPaiAPI() gin.HandlerFunc
HacPaiAPI is a reverse proxy for https://hacpai.com.
func IsReservedPath ¶
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
func RandImages ¶
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 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
Pipe configuration.
type MarkdownResult ¶
func Markdown ¶
func Markdown(mdText string) *MarkdownResult
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"` }
func NewPagination ¶
func NewPagination(currentPageNum, pageSize, windowSize, recordCount int) *Pagination
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.
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 }
func GetSession ¶
func GetSession(c *gin.Context) *SessionData
func (*SessionData) AvatarURLWithSize ¶
func (sd *SessionData) AvatarURLWithSize(size int) string
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.
Click to show internal directories.
Click to hide internal directories.