util

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2018 License: GPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

Package util defines variety of utilities.

Index

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.1.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 GetPage

func GetPage(c *gin.Context) int

func GetRemoteAddr added in v1.1.0

func GetRemoteAddr(c *gin.Context) string

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

func IsDomain

func IsDomain(s string) bool

func IsIP

func IsIP(s string) bool

func IsLetter

func IsLetter(r rune) bool

func IsReservedPath

func IsReservedPath(path string) bool

func IsWindows

func IsWindows() bool

IsWindows determines whether current OS is Windows.

func LoadConf

func LoadConf()

LoadConf loads the configurations. Command-line arguments will override configuration file.

func Pwd

func Pwd() string

Pwd gets the path of current working directory.

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

func RandInts

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

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

type MarkdownResult struct {
	ContentHTML  string
	AbstractText string
	ThumbURL     string
}

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.

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
}

func GetSession

func GetSession(c *gin.Context) *SessionData

func (*SessionData) AvatarURLWithSize

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

func (*SessionData) Save

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

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