本文整理匯總了Golang中github.com/fuxiaohei/GoBlog/app/utils.Now函數的典型用法代碼示例。如果您正苦於以下問題:Golang Now函數的具體用法?Golang Now怎麽用?Golang Now使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Now函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Rss
func Rss(ctx *GoInk.Context) {
baseUrl := model.GetSetting("site_url")
article, _ := model.GetPublishArticleList(1, 20)
author := model.GetUsersByRole("ADMIN")[0]
articleMap := make([]map[string]string, len(article))
for i, a := range article {
m := make(map[string]string)
m["Title"] = a.Title
m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
m["Author"] = author.Nick
str := utils.Markdown2Html(a.Content())
str = strings.Replace(str, `src="/`, `src="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
str = strings.Replace(str, `href="/`, `href="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
m["Desc"] = str
m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC822)
articleMap[i] = m
}
ctx.ContentType("application/rss+xml;charset=UTF-8")
bytes, e := ctx.App().View().Render("rss.xml", map[string]interface{}{
"Title": model.GetSetting("site_title"),
"Link": baseUrl,
"Desc": model.GetSetting("site_description"),
"Created": time.Unix(utils.Now(), 0).Format(time.RFC822),
"Articles": articleMap,
})
if e != nil {
panic(e)
}
ctx.Body = bytes
}
示例2: CreateComment
// CreateComment creates a comment and links it to the cid content.
func CreateComment(cid int, c *Comment) {
commentMaxId += Storage.TimeInc(4)
c.Id = commentMaxId
c.CreateTime = utils.Now()
c.Status = "check"
c.Cid = cid
// escape content
c.Content = strings.Replace(utils.Html2str(template.HTMLEscapeString(c.Content)), "\n", "<br/>", -1)
// if empty url, use # instead.
if c.Url == "" {
c.Url = "#"
}
// if admin comment, must be approved.
if c.IsAdmin {
c.Status = "approved"
} else {
// if common comment, get reader status for checking status.
r := c.GetReader()
if r != nil {
if r.Active {
c.Status = "approved"
}
} else {
CreateReader(c)
}
}
// update comment memory data
comments[c.Id] = c
commentsIndex = append([]int{c.Id}, commentsIndex...)
// append to content
content := GetContentById(cid)
content.Comments = append(content.Comments, c)
go SyncContent(content)
}
示例3: Feed
func Feed(context *GoInk.Context) {
baseUrl := model.GetSetting("site_url")
article, _ := model.GetArticleList(1, 20)
feed := new(feeds.Feed)
feed.Title = model.GetSetting("site_title")
feed.Link = &feeds.Link{Href: baseUrl}
feed.Description = model.GetSetting("site_description")
author := model.GetUsersByRole("ADMIN")[0]
feed.Author = &feeds.Author{author.Nick, author.Email}
feed.Items = make([]*feeds.Item, 0)
var create int64
if len(article) > 0 {
create = article[0].EditTime
} else {
create = utils.Now()
}
feed.Created = time.Unix(create, 0)
for _, a := range article {
item := new(feeds.Item)
item.Title = a.Title
item.Link = &feeds.Link{Href: path.Join(baseUrl, a.Link())}
item.Author = feed.Author
item.Created = time.Unix(a.CreateTime, 0)
item.Description = utils.Html2str(a.Summary())
feed.Items = append(feed.Items, item)
}
str, e := feed.ToRss()
if e != nil {
panic(e)
}
context.ContentType("application/rss+xml;charset=UTF-8")
context.Body = []byte(str)
}
示例4: SaveContent
// SaveContent saves changed content.
// It will re-generate related indexes.
func SaveContent(c *Content) {
c.EditTime = utils.Now()
// clean rendered cache text
c.textRendered = ""
generatePublishArticleIndex()
go SyncContent(c)
}
示例5: CreateComment
func CreateComment(cid int, c *Comment) {
commentMaxId += Storage.TimeInc(4)
c.Id = commentMaxId
c.CreateTime = utils.Now()
c.Status = "check"
c.Cid = cid
if c.Url == "" {
c.Url = "#"
}
if c.IsAdmin {
c.Status = "approved"
} else {
r := c.GetReader()
if r != nil {
if r.Active {
c.Status = "approved"
}
} else {
CreateReader(c)
}
}
// update comment memory data
comments[c.Id] = c
commentsIndex = append([]int{c.Id}, commentsIndex...)
// append to content
content := GetContentById(cid)
content.Comments = append(content.Comments, c)
go SyncContent(content)
}
示例6: RecycleMessages
func RecycleMessages() {
for i, m := range messages {
if m.CreateTime+3600*24*3 < utils.Now() {
messages = messages[:i]
return
}
}
}
示例7: CreateFile
func CreateFile(f *File) *File {
fileMaxId += Storage.TimeInc(3)
f.Id = fileMaxId
f.UploadTime = utils.Now()
f.IsUsed = true
f.Hits = 0
files = append([]*File{f}, files...)
go SyncFiles()
return f
}
示例8: CreateToken
// create new token from user and context.
func CreateToken(u *User, context *GoInk.Context, expire int64) *Token {
t := new(Token)
t.UserId = u.Id
t.CreateTime = utils.Now()
t.ExpireTime = t.CreateTime + expire
t.Value = utils.Sha1(fmt.Sprintf("%s-%s-%d-%d", context.Ip, context.UserAgent, t.CreateTime, t.UserId))
tokens[t.Value] = t
go SyncTokens()
return t
}
示例9: CreateUser
// create new user.
func CreateUser(u *User) error {
if GetUserByName(u.Email) != nil {
return errors.New("email-repeat")
}
userMaxId += Storage.TimeInc(5)
u.Id = userMaxId
u.CreateTime = utils.Now()
u.LastLoginTime = u.CreateTime
users = append(users, u)
go SyncUsers()
return nil
}
示例10: CreateMessage
func CreateMessage(tp string, data interface{}) *Message {
m := new(Message)
m.Type = tp
m.Data = messageGenerator[tp](data)
if m.Data == "" {
println("message generator returns empty")
return nil
}
m.CreateTime = utils.Now()
m.IsRead = false
messageMaxId += Storage.TimeInc(3)
m.Id = messageMaxId
messages = append([]*Message{m}, messages...)
SyncMessages()
return m
}
示例11: CreateContent
// create new content.
func CreateContent(c *Content, t string) (*Content, error) {
c2 := GetContentBySlug(c.Slug)
if c2 != nil {
return nil, errors.New("slug-repeat")
}
contentMaxId += Storage.TimeInc(3)
c.Id = contentMaxId
c.CreateTime = utils.Now()
c.EditTime = c.CreateTime
c.UpdateTime = c.CreateTime
c.Comments = make([]*Comment, 0)
c.Type = t
c.Hits = 1
contents[c.Id] = c
contentsIndex[c.Type] = append([]int{c.Id}, contentsIndex[c.Type]...)
go SyncContent(c)
return c, nil
}
示例12: SiteMap
func SiteMap(ctx *GoInk.Context) {
baseUrl := model.GetSetting("site_url")
println(baseUrl)
article, _ := model.GetPublishArticleList(1, 50)
navigators := model.GetNavigators()
now := time.Unix(utils.Now(), 0).Format(time.RFC3339)
articleMap := make([]map[string]string, len(article))
for i, a := range article {
m := make(map[string]string)
m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC3339)
articleMap[i] = m
}
navMap := make([]map[string]string, 0)
for _, n := range navigators {
m := make(map[string]string)
if n.Link == "/" {
continue
}
if strings.HasPrefix(n.Link, "/") {
m["Link"] = strings.Replace(baseUrl+n.Link, baseUrl+"/", baseUrl, -1)
} else {
m["Link"] = n.Link
}
m["Created"] = now
navMap = append(navMap, m)
}
ctx.ContentType("text/xml")
bytes, e := ctx.App().View().Render("sitemap.xml", map[string]interface{}{
"Title": model.GetSetting("site_title"),
"Link": baseUrl,
"Created": now,
"Articles": articleMap,
"Navigators": navMap,
})
if e != nil {
panic(e)
}
ctx.Body = bytes
}
示例13: DoInstall
func DoInstall() {
// origin from https://github.com/wendal/gor/blob/master/gor/gor.go
decoder := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(zipBytes))
b, _ := ioutil.ReadAll(decoder)
ioutil.WriteFile(tmpZipFile, b, os.ModePerm)
z, e := zip.Open(tmpZipFile)
if e != nil {
panic(e)
os.Exit(1)
}
z.ExtractTo("")
defer func() {
z.Close()
decoder = nil
os.Remove(tmpZipFile)
}()
ioutil.WriteFile(installLockFile, []byte(fmt.Sprint(utils.Now())), os.ModePerm)
println("install success")
}
示例14: IsValid
// check token is valid or expired.
func (t *Token) IsValid() bool {
if GetUserById(t.UserId) == nil {
return false
}
return t.ExpireTime > utils.Now()
}
示例15: CreateFilePath
func CreateFilePath(dir string, f *File) string {
os.MkdirAll(dir, os.ModePerm)
name := utils.DateInt64(utils.Now(), "YYYYMMDDHHmmss")
name += strconv.Itoa(Storage.TimeInc(10)) + path.Ext(f.Name)
return path.Join(dir, name)
}