util

package
v0.0.0-...-0ec75ca Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Package util defines variety of utilities.

Package util defines variety of utilities.

Package util includes internationalization related manipulations.

Index

Constants

View Source
const (
	PathRoot           = "/"
	PathStatic         = "/static"
	PathInit           = "/start"
	PathSearch         = "/search"
	PathBlog           = "/blog"
	PathDoc            = "/doc"
	PathBook           = "/book"
	PathNote           = "/note"
	PathGallery        = "/gallery"
	PathConsole        = "/console"
	PathWechat         = "/wechat"
	PathAdmin          = "/admin"
	PathAPI            = "/api"
	PathTheme          = "/theme"
	PathActivities     = "/activities"
	PathArchives       = "/archives"
	PathArticles       = "/articles"
	PathAuthors        = "/authors"
	PathCategories     = "/categories"
	PathTags           = "/tags"
	PathComments       = "/comments"
	PathAtom           = "/atom"
	PathRSS            = "/rss"
	PathOpensearch     = "/opensearch.xml"
	PathFavicon        = "/favicon.ico"
	PathSitemap        = "/sitemap.xml"
	PathHalt           = "/halt.html"
	PathRobots         = "/robots.txt"
	PathAPIsSymArticle = "/apis/symphony/article"
	PathAPIsSymComment = "/apis/symphony/comment"
	PathPlatInfo       = "/plat/info"
	PathManifest       = "/manifest.json"
)

Path prefixes.

View Source
const (
	CodeOk      = 0  // OK
	CodeErr     = -1 // general error
	CodeAuthErr = 2  // unauthenticated request
)

Result codes.

View Source
const DefaultTheme = "Koma"

DefaultTheme represents the default theme name.

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

URLHacPai is the URL of HacPai community.

View Source
const UserAgent = "Sand/" + Version + "; +https://github.com/lbb4511/sand"

UserAgent represents HTTP client user agent.

View Source
const Version = "0.1.1"

Version of Sand.

Variables

View Source
var MarkedAvailable = false
View Source
var Themes []string

Themes saves all theme names.

View Source
var ZeroPushTime, _ = time.Parse("2006-01-02 15:04:05", "2006-01-02 15:04:05")

ZeroPushTime represents zero push time.

Functions

func CurrentMillisecond

func CurrentMillisecond() uint64

CurrentMillisecond returns the current time in millisecond.

func GetLocalesNames

func GetLocalesNames() []string

GetLocalesNames gets names of all locales. Returns ["zh_CN", "en_US"] for example.

func GetMessage

func GetMessage(locale, key string) string

GetMessage gets a message with the specified locale and key.

func GetMessagef

func GetMessagef(locale, key string, a ...interface{}) string

GetMessagef gets a message with the specified locale, key and arguments

func GetMessages

func GetMessages(locale string) map[string]interface{}

GetMessages gets all messages with the specified locale.

func GetRemoteAddr

func GetRemoteAddr(c *gin.Context) string

GetRemoteAddr returns remote address of the context.

func GitHubUserInfo

func GitHubUserInfo(accessToken string) (ret map[string]interface{})

GitHubUserInfo returns GitHub user info specified by the given access token.

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 IsBot

func IsBot(uaStr string) bool

IsBot checks the specified user-agent is a bot.

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 IsReservedPath

func IsReservedPath(path string) bool

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

func RandAvatarData

func RandAvatarData() (ret []byte)

RandAvatarData returns random avatar image byte array data from Gravatar (http://www.gravatar.com). Sees https://github.com/lbb4511/sand/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 Templates

func Templates(ret *gin.Engine)

Templates returns a gin engine and binds controllers with request URLs.

Types

type Configuration

type Configuration struct {
	Server                string // server scheme, host and port
	StaticServer          string // static resources server scheme, host and port
	Root                  string // static console template file root
	StaticResourceVersion string // version of static resources
	RuntimeMode           string // runtime mode (dev/prod)
	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 second)
	SQLite                string // SQLite database file path
	MySQL                 string // MySQL connection URL
	Port                  string // listen port
	AxiosBaseURL          string // axio base URL
	MockServer            string // mock server
	DBsync                bool   // Database synchronization
}

Configuration (package.json).

var Conf *Configuration

Conf of sand.

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

Jump to

Keyboard shortcuts

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