當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。