当前位置: 首页>>代码示例>>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;未经允许,请勿转载。