Documentation ¶
Overview ¶
Package util defines variety of utilities.
Package util defines variety of utilities.
Package util includes internationalization related manipulations.
Index ¶
- Constants
- Variables
- func CurrentMillisecond() uint64
- func GetLocalesNames() []string
- func GetMessage(locale, key string) string
- func GetMessagef(locale, key string, a ...interface{}) string
- func GetMessages(locale string) map[string]interface{}
- func GetRemoteAddr(c *gin.Context) string
- func GitHubUserInfo(accessToken string) (ret map[string]interface{})
- func ImageSize(imageURL string, width, height int) string
- func IsBot(uaStr string) bool
- func IsDomain(s string) bool
- func IsIP(s string) bool
- func IsReservedPath(path string) bool
- func RandAvatarData() (ret []byte)
- func RandImage() string
- func RandImages(n int) []string
- func Templates(ret *gin.Engine)
- type Configuration
- type MarkdownResult
- type SessionData
Constants ¶
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.
const ( CodeOk = 0 // OK CodeErr = -1 // general error CodeAuthErr = 2 // unauthenticated request )
Result codes.
const DefaultTheme = "Koma"
DefaultTheme represents the default theme name.
const URLHacPai = "https://hacpai.com"
URLHacPai is the URL of HacPai community.
const UserAgent = "Sand/" + Version + "; +https://github.com/lbb4511/sand"
UserAgent represents HTTP client user agent.
const Version = "0.1.1"
Version of Sand.
Variables ¶
var MarkedAvailable = false
var Themes []string
Themes saves all theme names.
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 ¶
GetMessage gets a message with the specified locale and key.
func GetMessagef ¶
GetMessagef gets a message with the specified locale, key and arguments
func GetMessages ¶
GetMessages gets all messages with the specified locale.
func GetRemoteAddr ¶
GetRemoteAddr returns remote address of the context.
func GitHubUserInfo ¶
GitHubUserInfo returns GitHub user info specified by the given access token.
func ImageSize ¶
ImageSize returns image URL of Qiniu image processing style with the specified width and height.
func IsReservedPath ¶
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
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 ¶
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.