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


Golang util.Map函數代碼示例

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


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

示例1: Copy

// Copy.
//
// @param  dest string
// @param  args... bool
// @return map[string]interface{}, error
// @panics
func (this *Document) Copy(dest string, args ...bool) (map[string]interface{}, error) {
	id := this.GetId()
	if id == "" {
		panic("_id field could not be empty!")
	}
	if dest == "" {
		panic("Destination could not be empty!")
	}

	query, headers := util.Map(), util.Map()
	headers["Destination"] = dest

	if args != nil {
		if args[0] == true {
			query["batch"] = "ok"
		}
		if args[1] == true {
			headers["X-Couch-Full-Commit"] = "true"
		}
	}
	data, err := this.Database.Client.Copy(this.Database.Name+"/"+util.UrlEncode(id), query, headers).
		GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	return map[string]interface{}{
		"ok":  util.DigBool("ok", data),
		"id":  util.DigString("id", data),
		"rev": util.DigString("rev", data),
	}, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:38,代碼來源:document.go

示例2: CopyTo

// Copy to.
//
// @param  dest   string
// @param  destRev string
// @param  args... bool
// @return map[string]interface{}, error
// @panics
func (this *Document) CopyTo(dest, destRev string, args ...bool) (map[string]interface{}, error) {
	id, rev := this.GetId(), this.GetRev()
	if id == "" || rev == "" {
		panic("Both _id & _rev fields could not be empty!")
	}
	if dest == "" || destRev == "" {
		panic("Destination & destination revision could not be empty!")
	}

	query, headers := util.Map(), util.Map()
	headers["If-Match"] = rev
	headers["Destination"] = util.StringFormat("%s?rev=%s", dest, destRev)

	if args != nil {
		if args[0] == true {
			query["batch"] = "ok"
		}
		if args[1] == true {
			headers["X-Couch-Full-Commit"] = "true"
		}
	}

	data, err := this.Database.Client.Copy(this.Database.Name+"/"+util.UrlEncode(id), query, headers).
		GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	return map[string]interface{}{
		"ok":  util.DigBool("ok", data),
		"id":  util.DigString("id", data),
		"rev": util.DigString("rev", data),
	}, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:41,代碼來源:document.go

示例3: Remove

// Remove.
//
// @param  args... bool
// @return map[string]interface{}, error
// @panics
func (this *Document) Remove(args ...bool) (map[string]interface{}, error) {
	id, rev := this.GetId(), this.GetRev()
	if id == "" || rev == "" {
		panic("Both _id & _rev fields could not be empty!")
	}

	query, headers := util.Map(), util.Map()
	headers["If-Match"] = rev

	if args != nil {
		if args[0] == true {
			query["batch"] = "ok"
		}
		if args[1] == true {
			headers["X-Couch-Full-Commit"] = "true"
		}
	}

	data, err := this.Database.Client.Delete(this.Database.Name+"/"+util.UrlEncode(id), query, headers).
		GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	return map[string]interface{}{
		"ok":  util.DigBool("ok", data),
		"id":  util.DigString("id", data),
		"rev": util.DigString("rev", data),
	}, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:35,代碼來源:document.go

示例4: Replicate

// Create database.
//
// @param  target      string
// @param  targetCreate bool
// @return bool
func (this *Database) Replicate(
	target string, targetCreate bool) (map[string]interface{}, error) {
	// prepare body
	body := util.ParamList(
		"source", this.Name,
		"target", target,
		"create_target", targetCreate,
	)

	data, err := this.Client.Post("/_replicate", nil, body, nil).GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	ret := util.Map()
	for key, value := range data.(map[string]interface{}) {
		// grap, set & pass history field
		if key == "history" {
			ret[key] = util.MapList(value)
			for i, history := range value.([]interface{}) {
				ret[key].([]map[string]interface{})[i] = util.Map()
				for kkey, vvalue := range history.(map[string]interface{}) {
					ret[key].([]map[string]interface{})[i][kkey] = vvalue
				}
			}
			continue
		}
		ret[key] = value
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:37,代碼來源:database.go

示例5: Replicate

// Get UUID.
//
// @param  body map[string]interface{}
// @return map[string]interface{}, error
// @panics
func (this *Server) Replicate(body map[string]interface{}) (map[string]interface{}, error) {
	body = util.Param(body)
	if body["source"] == nil || body["target"] == nil {
		panic("Both source & target required!")
	}

	data, err := this.Client.Post("/_replicate", nil, body, nil).GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	ret := util.Map()
	for key, value := range data.(map[string]interface{}) {
		// grap, set & pass history field
		if key == "history" {
			ret["history"] = util.MapList(value)
			for i, history := range value.([]interface{}) {
				ret["history"].([]map[string]interface{})[i] = util.Map()
				for kkey, vvalue := range history.(map[string]interface{}) {
					ret["history"].([]map[string]interface{})[i][kkey] = vvalue
				}
			}
			continue
		}
		ret[key] = value
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:34,代碼來源:server.go

示例6: UpdateDocumentAll

// Update documents.
//
// @param  document []map[string]interface{}
// @return []map[string]interface{}, error
// @panics
func (this *Database) UpdateDocumentAll(
	documents []interface{}) ([]map[string]interface{}, error) {
	docs := util.MapList(documents)
	for i, doc := range documents {
		if docs[i] == nil {
			docs[i] = util.Map()
		}
		for key, value := range doc.(map[string]interface{}) {
			docs[i][key] = value
		}
		// these are required params
		if docs[i]["_id"] == nil || docs[i]["_rev"] == nil {
			panic("Both _id & _rev fields are required!")
		}
	}

	body := util.ParamList("docs", docs)
	data, err := this.Client.Post(this.Name+"/_bulk_docs", nil, body, nil).GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	ret := util.MapList(data)
	for i, doc := range data.([]interface{}) {
		if ret[i] == nil {
			ret[i] = util.Map()
		}

		for key, value := range doc.(map[string]interface{}) {
			ret[i][key] = value
		}
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:40,代碼來源:database.go

示例7: Ping

// Ping.
//
// @param  statusCodes... uint16
// @return bool
// @panics
func (this *DocumentAttachment) Ping(statusCodes ...uint16) bool {
	if this.Document == nil {
		panic("Attachment document is not defined!")
	}

	docId := this.Document.GetId()
	docRev := this.Document.GetRev()
	if docId == "" {
		panic("Attachment document _id is required!")
	}
	if this.FileName == "" {
		panic("Attachment file name is required!")
	}

	query, headers := util.Map(), util.Map()
	if docRev != "" {
		query["rev"] = docRev
	}
	if this.Digest != "" {
		headers["If-None-Match"] = util.Quote(this.Digest)
	}

	database := this.Document.GetDatabase()
	response := database.Client.Head(util.StringFormat("%s/%s/%s",
		database.Name, docId, util.UrlEncode(this.FileName)), query, headers)

	// try to match given status codes
	for _, statusCode := range statusCodes {
		if response.GetStatusCode() == statusCode {
			return true
		}
	}

	return false
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:40,代碼來源:document_attachment.go

示例8: Save

// Save.
//
// @param  args... bool
// @return map[string]interface{}, error
func (this *Document) Save(args ...bool) (map[string]interface{}, error) {
	query, headers, body := util.Map(), util.Map(), this.GetData()
	if args != nil {
		if args[0] == true {
			query["batch"] = "ok"
		}
		if args[1] == true {
			headers["X-Couch-Full-Commit"] = "true"
		}
	}

	if this.Rev != "" {
		headers["If-Match"] = this.Rev
	}

	if this.Attachments != nil {
		body["_attachments"] = util.Map()
		for name, attachment := range this.Attachments {
			body["_attachments"].(map[string]interface{})[name] = attachment.ToArray(true)
		}
	}

	// make a reusable lambda
	_func := func(data interface{}, err error) (map[string]interface{}, error) {
		if err != nil {
			return nil, err
		}

		id, rev := util.DigString("id", data), util.DigString("rev", data)
		// set id & rev for next save() instant calls
		if id != "" && this.Id == nil {
			this.SetId(id)
		}
		if rev != "" {
			this.SetRev(rev)
		}

		return map[string]interface{}{
			"ok":  util.DigBool("ok", data),
			"id":  id,
			"rev": rev,
		}, nil
	}

	if this.Id == nil {
		return _func( // insert action
			this.Database.Client.Post(this.Database.Name, query, body, headers).
				GetBodyData(nil))
	} else {
		return _func( // update action
			this.Database.Client.Put(this.Database.Name+"/"+this.GetId(), query, body, headers).
				GetBodyData(nil))
	}
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:58,代碼來源:document.go

示例9: GetDocument

// Get document.
//
// @param  key string
// @return map[string]interface{}, error
func (this *Database) GetDocument(key string) (map[string]interface{}, error) {
	// prepare query
	query := util.ParamList(
		"include_docs", true,
		"key", util.Quote(key),
	)

	data, err := this.Client.Get(this.Name+"/_all_docs", query, nil).
		GetBodyData(&DatabaseDocumentList{})
	if err != nil {
		return nil, err
	}

	ret := util.Map()

	for _, doc := range data.(*DatabaseDocumentList).Rows {
		ret["id"] = doc.Id
		ret["key"] = doc.Key
		ret["value"] = map[string]string{"rev": doc.Value["rev"].(string)}
		ret["doc"] = map[string]interface{}{}
		// fill doc field
		for key, value := range doc.Doc {
			ret["doc"].(map[string]interface{})[key] = value
		}
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:32,代碼來源:database.go

示例10: GetChanges

// Get changes.
//
// @param  query map[string]interface{}
// @return []map[string]interface{}, error
func (this *Database) GetChanges(
	query map[string]interface{}, docIds []string) (map[string]interface{}, error) {
	query = util.Param(query)
	if docIds != nil {
		query["filter"] = "_doc_ids"
	}

	body := util.ParamList("doc_ids", docIds)
	data, err := this.Client.Post(this.Name+"/_changes", query, body, nil).
		GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	ret := util.Map()
	ret["last_seq"] = util.Dig("last_seq", data)
	ret["results"] = util.MapList(0) // set empty as default
	if results := data.(map[string]interface{})["results"].([]interface{}); results != nil {
		ret["results"] = util.MapList(results) // @overwrite
		for i, result := range results {
			ret["results"].([]map[string]interface{})[i] = map[string]interface{}{
				"id":      util.Dig("id", result),
				"seq":     util.Dig("seq", result),
				"deleted": util.Dig("deleted", result),
				"changes": util.Dig("changes", result),
			}
		}
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:35,代碼來源:database.go

示例11: NewStream

// Constructor.
//
// @param  type_       uint8
// @param  httpVersion string
// @return couch.http.Stream
func NewStream(type_ uint8, httpVersion string) *Stream {
	return &Stream{
		Type:        type_,
		HttpVersion: httpVersion,
		Headers:     util.Map(),
	}
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:12,代碼來源:stream.go

示例12: GetMissingRevisions

// Get missing revisions.
//
// @param  object map[string]interface{}
// @return map[string]interface{}, error
func (this *Database) GetMissingRevisions(
	object map[string]interface{}) (map[string]interface{}, error) {
	data, err := this.Client.Post(this.Name+"/_missing_revs", nil, object, nil).GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	ret := util.Map()
	ret["missing_revs"] = util.Map()
	// fill missing revs
	for id, revs := range data.(map[string]interface{})["missing_revs"].(map[string]interface{}) {
		ret["missing_revs"].(map[string]interface{})[id] = revs
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:20,代碼來源:database.go

示例13: Purge

// Purge
//
// @param  object map[string]interface{}
// @return map[string]interface{}, error
func (this *Database) Purge(object map[string]interface{}) (map[string]interface{}, error) {
	data, err := this.Client.Post(this.Name+"/_purge", nil, object, nil).GetBodyData(nil)
	if err != nil {
		return nil, err
	}

	ret := util.Map()
	ret["purge_seq"] = util.DigInt("purge_seq", data)
	ret["purged"] = util.Map()
	// fill purged revs
	for id, revs := range data.(map[string]interface{})["purged"].(map[string]interface{}) {
		ret["purged"].(map[string]interface{})[id] = revs
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:20,代碼來源:database.go

示例14: ViewTemp

// View temp.
//
// @param  _map string
// @param  _red interface{}
// @return map[string]interface{}, error
func (this *Database) ViewTemp(_map string, _red interface{}) (map[string]interface{}, error) {
	body := util.ParamList(
		"map", _map,
		"reduce", util.IsEmptySet(_red, nil), // prevent "missing function" error
	)

	// short?
	type ddl DatabaseDocumentList

	data, err := this.Client.Post(this.Name+"/_temp_view", nil, body, nil).GetBodyData(&ddl{})
	if err != nil {
		return nil, err
	}

	ret := util.Map()
	ret["offset"] = data.(*ddl).Offset
	ret["total_rows"] = data.(*ddl).TotalRows

	rows := data.(*ddl).Rows
	ret["rows"] = util.MapList(len(rows))

	// append docs
	for i, row := range rows {
		ret["rows"].([]map[string]interface{})[i] = map[string]interface{}{
			"id":    row.Id,
			"key":   row.Key,
			"value": row.Value,
		}
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:37,代碼來源:database.go

示例15: FindAttachments

// Find attachments
//
// @param  attEncInfo bool
// @param  attsSince []string
// return  []map[string]interface{}, error
func (this *Document) FindAttachments(
	attEncInfo bool, attsSince []string) ([]map[string]interface{}, error) {
	query := util.Map()
	query["attachments"] = true
	query["att_encoding_info"] = attEncInfo

	if attsSince != nil {
		attsSinceArray := util.MapSliceString(attsSince)
		for _, attsSinceValue := range attsSince {
			attsSinceArray = append(attsSinceArray, util.QuoteEncode(attsSinceValue))
		}
	}

	data, err := this.Find(query)
	if err != nil {
		return nil, err
	}

	ret := util.MapList(nil)
	if data["_attachments"] != nil {
		for _, attc := range data["_attachments"].(map[string]interface{}) {
			ret = append(ret, attc.(map[string]interface{}))
		}
	}

	return ret, nil
}
開發者ID:yay-couch,項目名稱:couch-go,代碼行數:32,代碼來源:document.go


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