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


Golang bson.Now函数代码示例

本文整理汇总了Golang中labix/org/v2/mgo/bson.Now函数的典型用法代码示例。如果您正苦于以下问题:Golang Now函数的具体用法?Golang Now怎么用?Golang Now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Now函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CheckPass

func (this *Member) CheckPass(email string, password string) int {
	//验证登录信息
	err := memberC.Find(bson.M{"e": email}).One(&this)
	if err != nil {
		//处理错误
	}
	if bson.Now().Before(this.StopTime) { //锁定时间还没过
		return 0 //处于锁定状态
	}
	if this.Password == password {
		this.Error = 6
		this.Update(bson.M{"$set": bson.M{"er": this.Error}})
		return 1 //通过验证
	} else {
		if this.Error <= 1 {
			this.Error = 6
			minute := time.Duration(10) * time.Minute
			this.StopTime = bson.Now().Add(minute)
			this.Update(bson.M{"$set": bson.M{"er": this.Error, "st": this.StopTime}})
			return 2 //用户名或密码不正确
		} else {
			this.Error--
			this.Update(bson.M{"$set": bson.M{"er": this.Error}})
			return 2 //用户名或密码不正确
		}
	}
}
开发者ID:treejames,项目名称:Dream,代码行数:27,代码来源:member.go

示例2: SetTag

func (tag *TagWrapper) SetTag() error {
	c := DB.C("tags")
	var err error
	flag := false
	for _, v := range Tags {
		if tag.Name == v.Name {
			v.ArticleIds = append(v.ArticleIds, tag.ArticleIds...)
			removeDuplicate(&v.ArticleIds)
			v.Count = len(v.ArticleIds)
			v.ModifiedTime = bson.Now()
			err = c.UpdateId(v.Id_, v)
			flag = true
			break
		}
	}

	if !flag {
		tag.Id_ = bson.NewObjectId()
		tag.CreatedTime = bson.Now()
		tag.ModifiedTime = bson.Now()
		Tags = append(Tags, *tag)
		err = c.Insert(tag)
	}

	SetAppTags()
	return err
}
开发者ID:EPICPaaS,项目名称:MessageBlog,代码行数:27,代码来源:model.go

示例3: Post

func (this *RootArticleRouter) Post() {
	id := this.GetString("id")
	if len(this.Input()) == 1 { //删除操作
		models.DeleteArticle(&bson.M{"_id": bson.ObjectIdHex(id)})
		this.Data["json"] = true
		this.ServeJson(true)
	} else {
		nodename := this.GetString("selectnode")
		name := this.GetString("name")
		title := this.GetString("title")
		content := this.GetString("content")
		isThumbnail, _ := this.GetBool("isThumbnail")
		featuredPicURL := this.GetString("featuredPicURL")
		tags := this.GetStrings("tags")
		author, _ := this.GetSession("username").(string)
		cat := models.GetCategoryNodeName(nodename)
		if name == "" {
			name = strconv.Itoa(int(bson.Now().UnixNano()))
		}
		if id != "" {
			//更新
			article, _ := models.GetArticle(&bson.M{"_id": bson.ObjectIdHex(id)})
			article.CName = cat.Name
			article.NName = nodename
			article.Name = name
			article.Author = author
			article.Title = title
			article.Tags = tags
			article.FeaturedPicURL = featuredPicURL
			article.ModifiedTime = bson.Now()
			article.Text = template.HTML(content)
			article.IsThumbnail = isThumbnail

			article.SetSummary()
			article.UpdateArticle()
			this.Redirect("/root/article", 302)
		} else {
			//创建
			article := models.Article{
				CName:          cat.Name,
				NName:          nodename,
				Name:           name,
				Author:         author,
				Title:          title,
				Tags:           tags,
				FeaturedPicURL: featuredPicURL,
				CreatedTime:    bson.Now(),
				ModifiedTime:   bson.Now(),
				Text:           template.HTML(content),
				IsThumbnail:    isThumbnail,
			}
			article.SetSummary()
			article.CreatArticle()
			go Publish(&article)
			this.Redirect("/root/article", 302)
		}
	}

}
开发者ID:EPICPaaS,项目名称:MessageBlog,代码行数:59,代码来源:rootarticle.go

示例4: Post

func (this *RootNodeRouter) Post() {
	if len(this.Input()) == 2 { //删除操作
		cid := this.GetString("id")
		nname := this.GetString("nname")
		for _, v := range models.Categories {
			if v.Id_.Hex() == cid {
				for in, va := range v.Nodes {
					if va.Name == nname {
						v.Nodes = append(v.Nodes[:in], v.Nodes[(in+1):]...)
						break
					}
				}
				v.UpdateCategory()
				break
			}
		}
		this.Data["json"] = true
		this.ServeJson(true)
	} else {
		categoryid := this.GetString("selectcategory")
		name := this.GetString("name")
		title := this.GetString("title")
		content := this.GetString("content")
		if name == "" {
			name = strconv.Itoa(int(bson.Now().UnixNano()))
		}

		for _, v := range models.Categories {
			if v.Id_.Hex() == categoryid {
				flag := false
				for _, va := range v.Nodes {
					if va.Name == name { //更新
						va.Title = title
						va.Content = content
						va.UpdatedTime = bson.Now()
						flag = true
						break
					}
				}

				if !flag { //添加
					node := models.Node{
						Name:        name,
						Title:       title,
						Content:     content,
						CreatedTime: bson.Now(),
						UpdatedTime: bson.Now(),
					}
					v.Nodes = append(v.Nodes, node)
				}

				v.UpdateCategory()
				break
			}
		}
		this.Redirect("/root/node", 302)
	}
}
开发者ID:EPICPaaS,项目名称:MessageBlog,代码行数:58,代码来源:rootnode.go

示例5: Insert

func (this *Member) Insert() string {
	//插入数据
	this.Id = bson.NewObjectId()
	this.FirstTime = bson.Now()
	this.LastTime = bson.Now()
	err := memberC.Insert(this)
	if err != nil {
		panic(err)
	}
	return bson.ObjectId.Hex(this.Id)
}
开发者ID:treejames,项目名称:Dream,代码行数:11,代码来源:member.go

示例6: TestLockUpdatesExpires

func (s *StoreSuite) TestLockUpdatesExpires(c *C) {
	urlA := charm.MustParseURL("cs:oneiric/wordpress-a")
	urlB := charm.MustParseURL("cs:oneiric/wordpress-b")
	urls := []*charm.URL{urlA, urlB}

	// Initiate an update of B only to force a partial conflict.
	lock1, err := s.store.LockUpdates(urls[1:])
	c.Assert(err, IsNil)

	// Hack time to force an expiration.
	locks := s.Session.DB("juju").C("locks")
	selector := bson.M{"_id": urlB.String()}
	update := bson.M{"time": bson.Now().Add(-store.UpdateTimeout - 10e9)}
	err = locks.Update(selector, update)
	c.Check(err, IsNil)

	// Works due to expiration of previous lock.
	lock2, err := s.store.LockUpdates(urls)
	c.Assert(err, IsNil)
	defer lock2.Unlock()

	// The expired lock was forcefully killed. Unlocking it must
	// not interfere with lock2 which is still alive.
	lock1.Unlock()

	// The above statement was a NOOP and lock2 is still in effect,
	// so attempting another lock must necessarily fail.
	lock3, err := s.store.LockUpdates(urls)
	c.Check(err, Equals, store.ErrUpdateConflict)
	c.Check(lock3, IsNil)
}
开发者ID:rif,项目名称:golang-stuff,代码行数:31,代码来源:store_test.go

示例7: TestNow

func (s *S) TestNow(c *C) {
	before := time.Now()
	time.Sleep(1e6)
	now := bson.Now()
	time.Sleep(1e6)
	after := time.Now()
	c.Assert(now.After(before) && now.Before(after), Equals, true, Commentf("now=%s, before=%s, after=%s", now, before, after))
}
开发者ID:RyanDeng,项目名称:qbot,代码行数:8,代码来源:bson_test.go

示例8: TestReplyer

func TestReplyer(t *testing.T) {
	setUp(t)
	defer tearDown(t)

	var obj = Reply{
		ID:         "1234_abcxxxxxxxxxxxx",
		Error:      "Errare humanum est",
		StatusCode: 102,
		Header:     make(http.Header), // So it is retrieved from mongoDB. nil does not work
		Trailer:    make(http.Header), // So it is retrieved from mongoDB. nil does not work
		Proto:      "protocol",
		Body:       []byte{1, 2, 3, 0, 9, 8, 7},
		Done:       bson.Now(),
		Created:    bson.Now(),
	}

	replyer := &Replyer{Cfg: cfgTest, SessionSeed: sessionTest}
	db := sessionTest.DB(cfgTest.Database)
	respColl := db.C(cfgTest.ResponsesColl)
	respColl.Insert(obj)
	if err := sessionTest.Fsync(false); err != nil {
		t.Fatal(err)
	}
	request, err := http.NewRequest("GET", "/one/two/three/"+obj.ID, nil)
	if err != nil {
		t.Fatal(err)
	}
	response := httptest.NewRecorder()
	replyer.ServeHTTP(response, request)
	if response.Code != 200 {
		t.Errorf("response should be 200 for existent reply. reponse.Code %d", response.Code)
	}

	if contentType := response.Header().Get("Content-Type"); contentType != "application/json" {
		t.Errorf("content type of response should be \"application/json\". It is %q", contentType)
	}
	var objR = Reply{}
	err = json.Unmarshal(response.Body.Bytes(), &objR)
	if err != nil {
		t.Fatalf("%v : %q", err, response.Body.Bytes())
	}
	if !reflect.DeepEqual(obj, objR) {
		t.Error("response body should be equal to body reply %#v %#v", obj, objR)
	}

}
开发者ID:espencer,项目名称:gridas,代码行数:46,代码来源:replyer_test.go

示例9: PingSession

func (ts *TestStore) PingSession(s *Session) error {
	if tss, ok := ts.Sessions[s.Id]; ok {
		if tss.MachineId == s.MachineId && tss.ClosedAt.Equal(time.Time{}) {
			tss.LastPing = bson.Now()
			return nil
		}
	}
	return mgo.ErrNotFound
}
开发者ID:rhcarvalho,项目名称:elephant-tracker,代码行数:9,代码来源:api_test.go

示例10: NewInstallation

func NewInstallation(machineId, xmppvoxVersion string, dosvoxInfo, machineInfo map[string]string) *Installation {
	return &Installation{
		MachineId:      machineId,
		XMPPVOXVersion: xmppvoxVersion,
		DosvoxInfo:     dosvoxInfo,
		MachineInfo:    machineInfo,
		CreatedAt:      bson.Now(),
	}
}
开发者ID:rhcarvalho,项目名称:elephant-tracker,代码行数:9,代码来源:storage.go

示例11: process

//process recreates the request that should be sent to the target host
//it stores the response in the store of replies.
func (c *Consumer) process(petition *Petition) {
	var (
		req   *http.Request
		resp  *http.Response
		reply *Reply
		start = bson.Now()
	)

	db := c.SessionSeed.DB(c.Cfg.Database)
	petColl := db.C(c.Cfg.Instance + c.Cfg.PetitionsColl)
	replyColl := db.C(c.Cfg.ResponsesColl)
	errColl := db.C(c.Cfg.ErrorsColl)

	mylog.Debugf("processing petition %+v", petition)
	req, err := petition.Request()
	if err != nil {
		mylog.Alert(petition.ID, err)
		return
	}
	mylog.Debugf("restored request %+v", req)
	mylog.Debug("before making request", petition.ID)
	resp, err = c.doRequest(req, petition.ID)
	if err == nil {
		mylog.Debug("after making request", petition.ID)
		defer func() {
			mylog.Debug("closing response body", petition.ID)
			resp.Body.Close()
		}()
	}

	reply = newReply(resp, petition, err)
	reply.Created = start
	mylog.Debugf("created reply %+v", reply)
	if err != nil || resp.StatusCode < 200 || resp.StatusCode >= 300 {
		e := errColl.Insert(reply)
		if e != nil {
			mylog.Alert("ERROR inserting erroneous reply", petition.ID, err)
			c.SessionSeed.Refresh()
		}
	}
	mylog.Debugf("before insert reply %+v", reply)
	err = replyColl.Insert(reply)
	mylog.Debugf("after insert reply %+v", reply)
	if err != nil {
		mylog.Alert("ERROR inserting reply", petition.ID, err)
		c.SessionSeed.Refresh()
	}
	mylog.Debugf("before remove petition %+v", petition)
	err = petColl.Remove(bson.M{"id": petition.ID})
	mylog.Debugf("after remove petition %+v", petition)
	if err != nil {
		mylog.Alert("ERROR removing petition", petition.ID, err)
		c.SessionSeed.Refresh()
	}

}
开发者ID:espencer,项目名称:gridas,代码行数:58,代码来源:consumer.go

示例12: NewSession

func NewSession(jid, machineId, xmppvoxVersion string, r *HttpRequest) *Session {
	return &Session{
		Id:             bson.NewObjectId(),
		CreatedAt:      bson.Now(),
		JID:            jid,
		MachineId:      machineId,
		XMPPVOXVersion: xmppvoxVersion,
		Request:        r,
	}
}
开发者ID:rhcarvalho,项目名称:elephant-tracker,代码行数:10,代码来源:storage.go

示例13: SetTag

func SetTag(tag *TagWrapper) error {
	c := DB.C("tags")
	var oldtag TagWrapper
	err := c.Find(bson.M{"name": tag.Name}).One(&oldtag)
	if err != nil && err.Error() == "not found" {
		tag.Id_ = bson.NewObjectId()
		tag.CreatedTime = bson.Now()
		tag.ModifiedTime = bson.Now()
		c.Insert(tag)
	} else if err != nil {
		return err
	} else {
		oldtag.ArticleIds = append(oldtag.ArticleIds, tag.ArticleIds...)
		removeDuplicate(&oldtag.ArticleIds)
		oldtag.Count = len(oldtag.ArticleIds)
		oldtag.ModifiedTime = bson.Now()
		c.UpdateId(oldtag.Id_, oldtag)
	}
	return nil
}
开发者ID:pmljm,项目名称:MessageBlog,代码行数:20,代码来源:mongodb.go

示例14: CloseSession

func (m *MongoStore) CloseSession(s *Session) error {
	updateClosedTime := mgo.Change{
		Update:    bson.M{"$set": bson.M{"closed_at": bson.Now()}},
		ReturnNew: true,
	}
	_, err := m.C("sessions").Find(bson.M{
		"_id":        s.Id,
		"machine_id": s.MachineId,
		"closed_at":  time.Time{},
	}).Apply(updateClosedTime, &s)
	return err
}
开发者ID:rhcarvalho,项目名称:elephant-tracker,代码行数:12,代码来源:storage.go

示例15: Post

func (this *RootCategoryRouter) Post() {
	id := this.GetString("id")
	if len(this.Input()) == 1 { //删除操作
		models.DeleteCategory(&bson.M{"_id": bson.ObjectIdHex(id)})
		this.Data["json"] = true
		this.ServeJson(true)
	} else {
		name := this.GetString("name")
		title := this.GetString("title")
		content := this.GetString("content")
		if name == "" {
			name = strconv.Itoa(int(bson.Now().UnixNano()))
		}
		if id != "" {
			for _, v := range models.Categories {
				if v.Id_.Hex() == id {
					v.Name = name
					v.Title = title
					v.Content = content
					v.UpdatedTime = bson.Now()
					v.UpdateCategory()
					break
				}
			}
		} else {
			cat := models.Category{
				Id_:         bson.NewObjectId(),
				Name:        name,
				Title:       title,
				Content:     content,
				CreatedTime: bson.Now(),
				UpdatedTime: bson.Now(),
				NodeTime:    bson.Now(),
			}
			cat.CreatCategory()
		}

		this.Redirect("/root/category", 302)
	}
}
开发者ID:EPICPaaS,项目名称:MessageBlog,代码行数:40,代码来源:rootcategory.go


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