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


Golang Session.Close方法代码示例

本文整理汇总了Golang中labix/org/v2/mgo.Session.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Close方法的具体用法?Golang Session.Close怎么用?Golang Session.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在labix/org/v2/mgo.Session的用法示例。


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

示例1: SaveModel

// Save the DataModel to DataStore
func SaveModel(mgo_db string, m DataModel, conn *mgo.Session) (err error) {
	if conn == nil {
		conn, err = MgoConnGet(mgo_db)
		if err != nil {
			return
		}
		defer conn.Close()
	}
	if conn != nil {
		bsonMid := m.MidGet()
		c := conn.DB(mgo_db).C(m.Type())
		//Debug("SAVING ", mgo_db, " type=", m.Type(), " Mid=", bsonMid)
		if len(bsonMid) < 5 {
			m.MidSet(bson.NewObjectId())
			if err = c.Insert(m); err != nil {
				Log(ERROR, "MGOU ERROR on insert ", err, " TYPE=", m.Type(), " ", m.MidGet())
			} else {
				//Log(DEBUG, "successfully inserted!!!!!!  ", m.MidGet(), " oid=", m.OidGet())
			}
		} else {
			// YOU MUST NOT SEND Mid  "_id" to Mongo
			mid := m.MidGet()
			m.MidSet("") // omitempty means it doesn't get sent
			if err = c.Update(bson.M{"_id": bson.ObjectId(bsonMid)}, m); err != nil {
				Log(ERROR, "MGOU ERROR on update ", err, " ", bsonMid, " MID=?", m.MidGet())
			}
			m.MidSet(mid)
		}
	} else {
		Log(ERROR, "MGOU Nil connection")
		return errors.New("no db connection")
	}
	return
}
开发者ID:araddon,项目名称:mgou,代码行数:35,代码来源:store.go

示例2: Insert

// Save the DataModel to DataStore
func Insert(mgo_db string, m DataModel, conn *mgo.Session) (err error) {
	if conn == nil {
		conn, err = MgoConnGet(mgo_db)
		if err != nil {
			return
		}
		defer conn.Close()
	}
	if conn != nil {
		c := conn.DB(mgo_db).C(m.Type())
		if len(m.MidGet()) == 0 {
			m.MidSet(bson.NewObjectId())
		}
		if err = c.Insert(m); err != nil {
			Log(ERROR, "MGOU ERROR on insert ", err, " TYPE=", m.Type(), " ", m.MidGet())
		} else {
			//Log(DEBUG, "successfully inserted!!!!!!  ", m.MidGet(), " oid=", m.OidGet())
		}

	} else {
		Log(ERROR, "MGOU Nil connection")
		return errors.New("no db connection")
	}
	return
}
开发者ID:araddon,项目名称:mgou,代码行数:26,代码来源:store.go

示例3: newServer

func newServer() (*coretesting.MgoInstance, error) {
	inst := &coretesting.MgoInstance{Params: []string{"--replSet", name}}

	err := inst.Start(true)
	if err != nil {
		return nil, fmt.Errorf("Error starting mongo server: %s", err.Error())
	}

	// by dialing right now, we'll wait until it's running
	strategy := utils.AttemptStrategy{Total: time.Second * 5, Delay: time.Millisecond * 100}
	attempt := strategy.Start()
	for attempt.Next() {
		var session *mgo.Session
		session, err = inst.DialDirect()
		if err != nil {
			err = fmt.Errorf("Error dialing mongo server %q: %s", inst.Addr(), err.Error())
		} else {
			session.SetMode(mgo.Monotonic, true)
			err = session.Ping()
			if err != nil {
				err = fmt.Errorf("Error pinging mongo server %q: %s", inst.Addr(), err.Error())
			}
			session.Close()
		}
		if err == nil || !attempt.HasNext() {
			break
		}
	}
	return inst, err
}
开发者ID:jameinel,项目名称:core,代码行数:30,代码来源:replicaset_test.go

示例4: CloseSession

// CloseSession puts the connection back into the pool
func CloseSession(sessionId string, mongoSession *mgo.Session) {
	defer helper.CatchPanic(nil, sessionId, "CloseSession")

	tracelog.Started(sessionId, "CloseSession")
	mongoSession.Close()
	tracelog.Completed(sessionId, "CloseSession")
}
开发者ID:jharlap,项目名称:beego-mgo,代码行数:8,代码来源:mongo.go

示例5: CloseSession

func CloseSession(s *mgo.Session) {
	defer func() {
		if err := recover(); err != nil {
			log.Print("[MGO2_CLOSE_SESSION_RECOVER] close session panic", err)
		}
	}()
	s.Close()
}
开发者ID:RyanDeng,项目名称:qbot,代码行数:8,代码来源:mgo_db.go

示例6: checkServerStatus

// TODO remove dead session from freecon
func (this *Client) checkServerStatus(wg *sync.WaitGroup, sess *mgo.Session) {
	defer wg.Done()
	err := sess.Ping()
	if err != nil {
		log.Error("mongodb err: %v %s", sess.LiveServers(), err)
		sess.Close()
	}
}
开发者ID:justinblah,项目名称:fae,代码行数:9,代码来源:watchdog.go

示例7: CloseSession

// CloseSession puts the connection back into the pool
func CloseSession(sessionId string, mongoSession *mgo.Session) {
	defer helper.CatchPanic(nil, sessionId, "CloseSession")

	tracelog.STARTED(sessionId, "CloseSession")

	mongoSession.Close()

	tracelog.COMPLETED(sessionId, "CloseSession")
}
开发者ID:kelu95,项目名称:revel-mgo,代码行数:10,代码来源:mongo.go

示例8: insertworker

// insertworker calls func insertdoc for specified insert count
func insertworker(s *mgo.Session, ch chan int) {
	c := s.DB("test").C("mongotest")
	defer s.Close()
	for i := 0; i < Insert_Count; i++ {
		err := insertdoc(c, i)
		if err != nil {
			panic(err)
		}
	}
	ch <- 1
}
开发者ID:klydel,项目名称:random,代码行数:12,代码来源:mongotest.go

示例9: checkServerStatus

func (this *Client) checkServerStatus(wg *sync.WaitGroup, sess *mgo.Session) {
	defer wg.Done()
	err := sess.Ping()
	if err != nil {
		// TODO show mongodb uri in log
		log.Error("mongodb killed for: %s", err)

		sess.Close()
		this.killConn(sess)
	}
}
开发者ID:lucmichalski,项目名称:fae,代码行数:11,代码来源:watchdog.go

示例10: DeleteTodos

func DeleteTodos(resp http.ResponseWriter, req *http.Request,
	b *Broker, session *mgo.Session) {
	defer session.Close()
	var todos []string
	if ReadJson(req.Body, &todos) == nil {
		collection := TodoCollection(session)
		collection.RemoveAll(bson.M{"guid": bson.M{"$in": todos}})
		for _, todo := range todos {
			message := &Message{"delete", todo}
			b.messages <- message
		}
	}
}
开发者ID:rmorriso,项目名称:golang-sse-todo,代码行数:13,代码来源:todo.go

示例11: SaveTodo

func SaveTodo(resp http.ResponseWriter, req *http.Request,
	b *Broker, session *mgo.Session) {
	defer session.Close()
	var todo = new(Todo)
	if err := todo.ReadJson(req.Body); err != nil {
		http.Error(resp, "Bad Request", http.StatusBadRequest)
	} else {
		collection := TodoCollection(session)
		collection.Upsert(bson.M{"guid": todo.Guid}, todo)
		message := &Message{"update", todo.ToJsonString()}
		b.messages <- message
	}
}
开发者ID:rmorriso,项目名称:golang-sse-todo,代码行数:13,代码来源:todo.go

示例12: putFreeConn

func (this *Client) putFreeConn(uri string, sess *mgo.Session) {
	this.lk.Lock()
	defer this.lk.Unlock()
	if this.freeconns == nil {
		this.freeconns = make(map[string][]*mgo.Session)
	}
	freelist := this.freeconns[uri]
	if len(freelist) >= this.conf.MaxIdleConnsPerServer {
		sess.Close()
		return
	}
	this.freeconns[uri] = append(this.freeconns[uri], sess)
}
开发者ID:lucmichalski,项目名称:fae,代码行数:13,代码来源:client.go

示例13: QueueTodos

func QueueTodos(session *mgo.Session, messageChan chan *Message) {
	var todos []Todo
	defer session.Close()
	collection := TodoCollection(session)
	iter := collection.Find(nil).Iter()
	err := iter.All(&todos)
	if err != nil {
		return
	}
	for _, todo := range todos {
		message := &Message{"update", todo.ToJsonString()}
		messageChan <- message
	}
}
开发者ID:rmorriso,项目名称:golang-sse-todo,代码行数:14,代码来源:todo.go

示例14: main

// Serve sshkeys at http://:33845/{boxname}
func main() {
	defer func() {
		if err := recover(); err != nil {
			panic(err)
		}
	}()

	var session *mgo.Session
	var err error

	go func() {
		for session == nil {
			log.Println("Connecting to mongo..")

			session, err = mgo.Dial(os.Getenv("CU_DB"))

			if err != nil {
				if session != nil {
					session.Close()
					session = nil
				}
				log.Printf("Database connection failed (%q), retrying..", err)
				time.Sleep(10 * time.Second)
			}
		}
		log.Println("Connected to mongo.")
	}()

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		u := r.URL.Path[1:]
		if session == nil {
			log.Printf("%v StatusServiceUnavailable session == nil", u)
			w.WriteHeader(http.StatusServiceUnavailable)
			return
		}

		boxUsers, allUsers, keys := getKeys(session, u)

		log.Printf("%s:%v:%q:%q", u, strings.Count(keys, "\n"), boxUsers, allUsers)
		fmt.Fprint(w, keys)
	})

	log.Println("Serving..")
	err = http.ListenAndServe("localhost:33845", nil)
	check(err)
}
开发者ID:scraperwiki,项目名称:cobalt,代码行数:47,代码来源:main.go

示例15: releaseMongo

func releaseMongo(session *mgo.Session, db *mgo.Database) {
	mongo, _ := Application.Config["mongo"].(map[string]interface{})

	keep_db, ok := mongo["keep_test_db"].(bool)
	if !ok {
		keep_db = false
	}

	if !keep_db {
		fmt.Println("Testing finished... Dropping database")
		db.DropDatabase()
	} else {
		fmt.Println("Keep test database is true, not dropping database after unit test")
	}

	session.Close()
}
开发者ID:johnnadratowski,项目名称:authorizer,代码行数:17,代码来源:handlers_test.go


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