當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Session.Clone方法代碼示例

本文整理匯總了Golang中labix/org/v2/mgo.Session.Clone方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Clone方法的具體用法?Golang Session.Clone怎麽用?Golang Session.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在labix/org/v2/mgo.Session的用法示例。


在下文中一共展示了Session.Clone方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: New

// New returns a new mongo store
func New(session mgo.Session, database string, collection string, maxAge int, ensureTTL bool, keyPairs ...[]byte) nSessions.Store {

	if ensureTTL {
		conn := session.Clone()
		defer conn.Close()
		db := conn.DB(database)
		c := db.C(collection)
		c.EnsureIndex(mgo.Index{
			Key:         []string{"modified"},
			Background:  true,
			Sparse:      true,
			ExpireAfter: time.Duration(maxAge) * time.Second,
		})
	}
	return &mongoStore{
		Codecs:     securecookie.CodecsFromPairs(keyPairs...),
		Token:      nSessions.NewCookieToken(),
		session:    session,
		database:   database,
		collection: collection,
		options: &gSessions.Options{
			MaxAge: maxAge,
		},
	}
}
開發者ID:jmptrader,項目名稱:Negroni-Example,代碼行數:26,代碼來源:main.go

示例2: Initiate

// Initiate sets up a replica set with the given replica set name with the
// single given member.  It need be called only once for a given mongo replica
// set.  The tags specified will be added as tags on the member that is created
// in the replica set.
//
// Note that you must set DialWithInfo and set Direct = true when dialing into a
// specific non-initiated mongo server.
//
// See http://docs.mongodb.org/manual/reference/method/rs.initiate/ for more
// details.
func Initiate(session *mgo.Session, address, name string, tags map[string]string) error {
	monotonicSession := session.Clone()
	defer monotonicSession.Close()
	monotonicSession.SetMode(mgo.Monotonic, true)
	cfg := Config{
		Name:    name,
		Version: 1,
		Members: []Member{{
			Id:      1,
			Address: address,
			Tags:    tags,
		}},
	}
	logger.Infof("Initiating replicaset with config %#v", cfg)
	var err error
	for i := 0; i < maxInitiateAttempts; i++ {
		err = monotonicSession.Run(bson.D{{"replSetInitiate", cfg}}, nil)
		if err != nil && err.Error() == rsMembersUnreachableError {
			time.Sleep(initiateAttemptDelay)
			continue
		}
		break
	}

	return err
}
開發者ID:rogpeppe,項目名稱:juju,代碼行數:36,代碼來源:replicaset.go

示例3: getKeys

// Get the list of all SSH keys allowed to access a box.
func getKeys(session *mgo.Session, boxname string) (boxUsers, usernames []string, keys string) {

	this_session := session.Clone()
	defer this_session.Close()

	db := this_session.DB("")

	staff := getStaff(db)
	boxUsers = usersFromBox(db, boxname)

	usernames = combineUsers(staff, boxUsers) // returned

	// Looks through `canBeReally`.
	keySlice := allKeysFromUsernames(db, usernames)

	for _, k := range keySlice {
		k = strings.Replace(k, "\n", "", -1)
		if !strings.HasPrefix(k, "ssh-") && !strings.HasPrefix(k, "#") {
			keys += "# NOT VAILD: "
		}
		keys += k + "\n"
	}

	return
}
開發者ID:scraperwiki,項目名稱:cobalt,代碼行數:26,代碼來源:main.go

示例4: db

func db(session *mgo.Session) martini.Handler {
	// each request will have its own session
	return func(c martini.Context) {
		s := session.Clone()
		c.Map(s.DB("GoThere"))
		defer s.Close()
		c.Next()
	}
}
開發者ID:K-Phoen,項目名稱:BeThere,代碼行數:9,代碼來源:api.go

示例5: CurrentConfig

// CurrentConfig returns the Config for the given session's replica set.  If
// there is no current config, the error returned will be mgo.ErrNotFound.
func CurrentConfig(session *mgo.Session) (*Config, error) {
	cfg := &Config{}
	monotonicSession := session.Clone()
	monotonicSession.SetMode(mgo.Monotonic, true)
	err := monotonicSession.DB("local").C("system.replset").Find(nil).One(cfg)
	if err == mgo.ErrNotFound {
		return nil, err
	}
	if err != nil {
		return nil, fmt.Errorf("cannot get replset config: %s", err.Error())
	}
	return cfg, nil
}
開發者ID:jameinel,項目名稱:core,代碼行數:15,代碼來源:replicaset.go

示例6: Initiate

// Initiate sets up a replica set with the given replica set name with the
// single given member.  It need be called only once for a given mongo replica
// set.  The tags specified will be added as tags on the member that is created
// in the replica set.
//
// Note that you must set DialWithInfo and set Direct = true when dialing into a
// specific non-initiated mongo server.
//
// See http://docs.mongodb.org/manual/reference/method/rs.initiate/ for more
// details.
func Initiate(session *mgo.Session, address, name string, tags map[string]string) error {
	monotonicSession := session.Clone()
	monotonicSession.SetMode(mgo.Monotonic, true)
	cfg := Config{
		Name:    name,
		Version: 1,
		Members: []Member{{
			Id:      1,
			Address: address,
			Tags:    tags,
		}},
	}
	logger.Infof("Initiating replicaset with config %#v", cfg)
	return monotonicSession.Run(bson.D{{"replSetInitiate", cfg}}, nil)
}
開發者ID:jameinel,項目名稱:core,代碼行數:25,代碼來源:replicaset.go

示例7: Initiate

// Initiate sets up a replica set with the given replica set name with the
// single given member.  It need be called only once for a given mongo replica
// set.  The tags specified will be added as tags on the member that is created
// in the replica set.
//
// Note that you must set DialWithInfo and set Direct = true when dialing into a
// specific non-initiated mongo server.
//
// See http://docs.mongodb.org/manual/reference/method/rs.initiate/ for more
// details.
func Initiate(session *mgo.Session, address, name string, tags map[string]string) error {
	monotonicSession := session.Clone()
	defer monotonicSession.Close()
	monotonicSession.SetMode(mgo.Monotonic, true)
	cfg := Config{
		Name:    name,
		Version: 1,
		Members: []Member{{
			Id:      1,
			Address: address,
			Tags:    tags,
		}},
	}
	logger.Infof("Initiating replicaset with config %#v", cfg)
	var err error
	for i := 0; i < maxInitiateAttempts; i++ {
		monotonicSession.Refresh()
		err = monotonicSession.Run(bson.D{{"replSetInitiate", cfg}}, nil)
		if err != nil && err.Error() == rsMembersUnreachableError {
			time.Sleep(initiateAttemptDelay)
			continue
		}
		break
	}

	// Wait for replSetInitiate to complete. Even if err != nil,
	// it may be that replSetInitiate is still in progress, so
	// attempt CurrentStatus.
	for i := 0; i < maxInitiateStatusAttempts; i++ {
		monotonicSession.Refresh()
		var status *Status
		status, err = getCurrentStatus(monotonicSession)
		if err != nil {
			logger.Warningf("Initiate: fetching replication status failed: %v", err)
		}
		if err != nil || len(status.Members) == 0 {
			time.Sleep(initiateAttemptStatusDelay)
			continue
		}
		break
	}
	return err
}
開發者ID:jimmiebtlr,項目名稱:juju,代碼行數:53,代碼來源:replicaset.go

示例8: MgoSessionInjectFilterFunc

// 創建revel_session 注入過濾器
func MgoSessionInjectFilterFunc(session *mgo.Session) func(c *revel.Controller, fc []revel.Filter) {
	return func(c *revel.Controller, fc []revel.Filter) {
		appCtrl := c.AppController
		typeOfC := reflect.TypeOf(appCtrl).Elem()
		_, ok := typeOfC.FieldByName("MSession")
		if !ok {
			fc[0](c, fc[1:])
			return
		}
		valueOfC := reflect.ValueOf(appCtrl).Elem()
		// 注入 session
		newSession := session.Clone()
		defer newSession.Close()
		valueOfSession := reflect.ValueOf(newSession)
		valoeOfElem := valueOfC.FieldByName("MSession")
		valoeOfElem.Set(valueOfSession)
		fc[0](c, fc[1:])
	}
}
開發者ID:wangboo,項目名稱:gutil,代碼行數:20,代碼來源:session_inject.go

示例9: Register

func Register(dbsess *mgo.Session, dbname string) {
	DefaultProvider.DBSess = dbsess.Clone()
	DefaultProvider.DBName = dbname
}
開發者ID:kidstuff,項目名稱:WebAuth,代碼行數:4,代碼來源:mgoauth.go


注:本文中的labix/org/v2/mgo.Session.Clone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。