当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.Now函数代码示例

本文整理汇总了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
}
开发者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


注:本文中的github.com/fuxiaohei/GoBlog/app/utils.Now函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。