本文整理汇总了Golang中github.com/fuxiaohei/GoBlog/app/utils.Now函数的典型用法代码示例。如果您正苦于以下问题:Golang Now函数的具体用法?Golang Now怎么用?Golang Now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Now函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:33,代码来源:rss.go
示例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)
}
开发者ID:carriercomm,项目名称:GoBlog,代码行数:35,代码来源:comment.go
示例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)
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:33,代码来源:rss.go
示例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)
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:9,代码来源:content.go
示例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)
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:29,代码来源:comment.go
示例6: RecycleMessages
func RecycleMessages() {
for i, m := range messages {
if m.CreateTime+3600*24*3 < utils.Now() {
messages = messages[:i]
return
}
}
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:8,代码来源:message.go
示例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
}
开发者ID:carriercomm,项目名称:GoBlog,代码行数:10,代码来源:file.go
示例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
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:11,代码来源:token.go
示例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
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:13,代码来源:user.go
示例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
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:16,代码来源:message.go
示例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
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:19,代码来源:content.go
示例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
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:44,代码来源:rss.go
示例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")
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:19,代码来源:install.go
示例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()
}
开发者ID:flying99999,项目名称:GoBlog,代码行数:7,代码来源:token.go
示例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)
}
开发者ID:carriercomm,项目名称:GoBlog,代码行数:6,代码来源:file.go
示例16: LogError
// LogErrors logs error bytes to tmp/log directory.
func LogError(bytes []byte) {
dir := App.Config().String("app.log_dir")
file := path.Join(dir, utils.DateInt64(utils.Now(), "MMDDHHmmss.log"))
ioutil.WriteFile(file, bytes, os.ModePerm)
}
开发者ID:carriercomm,项目名称:GoBlog,代码行数:6,代码来源:log.go
示例17: writeDefaultData
func writeDefaultData() {
// write user
u := new(User)
u.Id = Storage.TimeInc(10)
u.Name = "admin"
u.Password = utils.Sha1("adminxxxxx")
u.Nick = "管理员"
u.Email = "[email protected]"
u.Url = "http://example.com/"
u.CreateTime = utils.Now()
u.Bio = "这是站点的管理员,你可以添加一些个人介绍,支持换行不支持markdown"
u.LastLoginTime = u.CreateTime
u.Role = "ADMIN"
Storage.Set("users", []*User{u})
// write token
Storage.Set("tokens", map[string]*Token{})
// write contents
a := new(Content)
a.Id = Storage.TimeInc(9)
a.Title = "欢迎使用 Fxh.Go"
a.Slug = "welcome-fxh-go"
a.Text = "如果您看到这篇文章,表示您的 blog 已经安装成功."
a.Tags = []string{"Fxh.Go"}
a.CreateTime = utils.Now()
a.EditTime = a.CreateTime
a.UpdateTime = a.CreateTime
a.IsComment = true
a.IsLinked = false
a.AuthorId = u.Id
a.Type = "article"
a.Status = "publish"
a.Format = "markdown"
a.Template = "blog.html"
a.Hits = 1
// write comments
co := new(Comment)
co.Author = u.Nick
co.Email = u.Email
co.Url = u.Url
co.Content = "欢迎加入使用 Fxh.Go"
co.Avatar = utils.Gravatar(co.Email, "50")
co.Pid = 0
co.Ip = "127.0.0.1"
co.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17"
co.IsAdmin = true
co.Id = Storage.TimeInc(7)
co.CreateTime = utils.Now()
co.Status = "approved"
co.Cid = a.Id
a.Comments = []*Comment{co}
Storage.Set("content/article-"+strconv.Itoa(a.Id), a)
// write pages
p := new(Content)
p.Id = a.Id + Storage.TimeInc(6)
p.Title = "关于"
p.Slug = "about-me"
p.Text = "本页面由 Fxh.Go 创建, 这只是个测试页面."
p.Tags = []string{}
p.CreateTime = utils.Now()
p.EditTime = p.CreateTime
p.UpdateTime = p.UpdateTime
p.IsComment = true
p.IsLinked = true
p.AuthorId = u.Id
p.Type = "page"
p.Status = "publish"
p.Format = "markdown"
p.Comments = make([]*Comment, 0)
p.Template = "page.html"
p.Hits = 1
Storage.Set("content/page-"+strconv.Itoa(p.Id), p)
p2 := new(Content)
p2.Id = p.Id + Storage.TimeInc(6)
p2.Title = "好友"
p2.Slug = "friends"
p2.Text = "本页面由 Fxh.Go 创建, 这只是个测试页面."
p2.Tags = []string{}
p2.CreateTime = utils.Now()
p2.EditTime = p2.CreateTime
p2.UpdateTime = p2.UpdateTime
p2.IsComment = true
p2.IsLinked = true
p2.AuthorId = u.Id
p2.Type = "page"
p2.Status = "publish"
p2.Format = "markdown"
p2.Comments = make([]*Comment, 0)
p2.Template = "page.html"
p2.Hits = 1
Storage.Set("content/page-"+strconv.Itoa(p2.Id), p2)
// write new reader
Storage.Set("readers", map[string]*Reader{})
// write version
v := new(version)
v.Name = "Fxh.Go"
//.........这里部分代码省略.........
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:101,代码来源:storage.go
示例18: TimeInc
func (jss *jsonStorage) TimeInc(d int) int {
return int(utils.Now())%d + 1
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:3,代码来源:storage.go
示例19: DoInstall
func DoInstall() {
ExtractBundleBytes()
ioutil.WriteFile(installLockFile, []byte(fmt.Sprint(utils.Now())), os.ModePerm)
println("install success")
}
开发者ID:carriercomm,项目名称:GoBlog,代码行数:5,代码来源:install.go
示例20: SaveContent
// save changed content.
func SaveContent(c *Content) {
c.EditTime = utils.Now()
go SyncContent(c)
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:5,代码来源:content.go
注:本文中的github.com/fuxiaohei/GoBlog/app/utils.Now函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论