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


Golang llmgo.Session類代碼示例

本文整理匯總了Golang中github.com/10gen/llmgo.Session的典型用法代碼示例。如果您正苦於以下問題:Golang Session類的具體用法?Golang Session怎麽用?Golang Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: Execute

// Execute performs the DeleteOp on a given session, yielding the reply when
// successful (and an error otherwise).
func (op *DeleteOp) Execute(session *mgo.Session) (Replyable, error) {
	session.SetSocketTimeout(0)
	if err := mgo.ExecOpWithoutReply(session, &op.DeleteOp); err != nil {
		return nil, err
	}
	return nil, nil
}
開發者ID:Machyne,項目名稱:mongo,代碼行數:9,代碼來源:delete_op.go

示例2: Execute

// Execute performs the GetMoreOp on a given session, yielding the reply when
// successful (and an error otherwise).
func (op *GetMoreOp) Execute(session *mgo.Session) (Replyable, error) {
	session.SetSocketTimeout(0)
	before := time.Now()

	_, _, data, resultReply, err := mgo.ExecOpWithReply(session, &op.GetMoreOp)
	after := time.Now()

	mgoReply, ok := resultReply.(*mgo.ReplyOp)
	if !ok {
		panic("reply from execution was not the correct type")
	}

	reply := &ReplyOp{
		ReplyOp: *mgoReply,
		Docs:    make([]bson.Raw, 0, len(data)),
	}

	for _, d := range data {
		dataDoc := bson.Raw{}
		err = bson.Unmarshal(d, &dataDoc)
		if err != nil {
			return nil, err
		}
		reply.Docs = append(reply.Docs, dataDoc)
	}

	reply.Latency = after.Sub(before)
	return reply, nil
}
開發者ID:Machyne,項目名稱:mongo,代碼行數:31,代碼來源:getmore_op.go

示例3: getTestDBPort

func getTestDBPort(session *mgo.Session) (string, error) {
	if port := os.Getenv("DB_PORT"); port != "" {
		return port, nil
	}

	result := struct {
		Members []struct {
			Name     string `bson:"name"`
			StateStr string `bson:"stateStr"`
		} `bson:"members"`
	}{}

	err := session.DB("admin").Run("replSetGetStatus", &result)
	if err != nil && err.Error() != "not running with --replSet" {
		return "", err
	}

	if err != nil && err.Error() == "not running with --replSet" {
		return fmt.Sprintf("%d", defaultTestPort), nil
	}

	for _, member := range result.Members {
		if member.StateStr == "PRIMARY" {
			return strings.Split(member.Name, ":")[1], nil
		}
	}

	return "", fmt.Errorf("unable to determine database port")
}
開發者ID:gabrielrussell,項目名稱:mongo-tools,代碼行數:29,代碼來源:play_livedb_test.go

示例4: getPrimaryPort

func getPrimaryPort(session *mgo.Session) (string, error) {

	result := struct {
		Members []struct {
			Name     string `bson:"name"`
			StateStr string `bson:"stateStr"`
		} `bson:"members"`
	}{}

	res := &struct {
		Msg string
	}{}
	session.Run("ismaster", res)
	isMongosTestServer = (res.Msg == "isdbgrid")
	if isMongosTestServer {
		return "", nil
	}

	err := session.DB("admin").Run("replSetGetStatus", &result)

	if err != nil {
		if err.Error() == "not running with --replSet" {
			return "", nil
		}
		return "", err
	}

	for _, member := range result.Members {
		if member.StateStr == "PRIMARY" {
			return strings.Split(member.Name, ":")[1], nil
		}
	}

	return "", fmt.Errorf("replset status has no primary")
}
開發者ID:Machyne,項目名稱:mongo,代碼行數:35,代碼來源:play_livedb_test.go

示例5: Execute

// Execute performs the CommandOp on a given session, yielding the reply when
// successful (and an error otherwise).
func (op *CommandOp) Execute(session *mgo.Session) (Replyable, error) {
	session.SetSocketTimeout(0)

	before := time.Now()
	metadata, commandReply, replyData, resultReply, err := mgo.ExecOpWithReply(session, &op.CommandOp)
	after := time.Now()
	if err != nil {
		return nil, err
	}
	mgoCommandReplyOp, ok := resultReply.(*mgo.CommandReplyOp)
	if !ok {
		panic("reply from execution was not the correct type")
	}
	commandReplyOp := &CommandReplyOp{
		CommandReplyOp: *mgoCommandReplyOp,
	}

	commandReplyOp.Metadata = &bson.Raw{}
	err = bson.Unmarshal(metadata, commandReplyOp.Metadata)
	if err != nil {
		return nil, err
	}
	commandReplyAsRaw := &bson.Raw{}
	err = bson.Unmarshal(commandReply, commandReplyAsRaw)
	if err != nil {
		return nil, err
	}
	commandReplyOp.CommandReply = commandReplyAsRaw
	doc := &struct {
		Cursor struct {
			FirstBatch []bson.Raw `bson:"firstBatch"`
			NextBatch  []bson.Raw `bson:"nextBatch"`
		} `bson:"cursor"`
	}{}
	err = commandReplyAsRaw.Unmarshal(&doc)
	if err != nil {
		return nil, err
	}

	if doc.Cursor.FirstBatch != nil {
		commandReplyOp.Docs = doc.Cursor.FirstBatch
	} else if doc.Cursor.NextBatch != nil {
		commandReplyOp.Docs = doc.Cursor.NextBatch
	}

	for _, d := range replyData {
		dataDoc := &bson.Raw{}
		err = bson.Unmarshal(d, &dataDoc)
		if err != nil {
			return nil, err
		}
		commandReplyOp.OutputDocs = append(commandReplyOp.OutputDocs, dataDoc)
	}
	commandReplyOp.Latency = after.Sub(before)
	return commandReplyOp, nil

}
開發者ID:Machyne,項目名稱:mongo,代碼行數:59,代碼來源:command_op.go


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