当前位置: 首页>>代码示例>>Golang>>正文


Golang TimedSet.Contains方法代码示例

本文整理汇总了Golang中github.com/couchbaselabs/sync_gateway/channels.TimedSet.Contains方法的典型用法代码示例。如果您正苦于以下问题:Golang TimedSet.Contains方法的具体用法?Golang TimedSet.Contains怎么用?Golang TimedSet.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/couchbaselabs/sync_gateway/channels.TimedSet的用法示例。


在下文中一共展示了TimedSet.Contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: handleAllDocs

// HTTP handler for _all_docs
func (h *handler) handleAllDocs() error {
	// http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
	includeDocs := h.getBoolQuery("include_docs")
	includeChannels := h.getBoolQuery("channels")
	includeAccess := h.getBoolQuery("access") && h.user == nil
	includeRevs := h.getBoolQuery("revs")
	includeSeqs := h.getBoolQuery("update_seq")

	// Get the doc IDs if this is a POST request:
	var explicitDocIDs []string
	if h.rq.Method == "POST" {
		input, err := h.readJSON()
		if err == nil {
			keys, ok := input["keys"].([]interface{})
			explicitDocIDs = make([]string, len(keys))
			for i := 0; i < len(keys); i++ {
				if explicitDocIDs[i], ok = keys[i].(string); !ok {
					break
				}
			}
			if !ok {
				err = base.HTTPErrorf(http.StatusBadRequest, "Bad/missing keys")
			}
		}
	}

	// Get the set of channels the user has access to; nil if user is admin or has access to "*"
	var availableChannels channels.TimedSet
	if h.user != nil {
		availableChannels = h.user.InheritedChannels()
		if availableChannels == nil {
			panic("no channels for user?")
		}
		if availableChannels.Contains("*") {
			availableChannels = nil
		}
	}

	// Subroutines that filter a channel list down to the ones that the user has access to:
	filterChannels := func(channels []string) []string {
		if availableChannels == nil {
			return channels
		}
		dst := 0
		for _, ch := range channels {
			if availableChannels.Contains(ch) {
				channels[dst] = ch
				dst++
			}
		}
		if dst == 0 {
			return nil
		}
		return channels[0:dst]
	}
	filterChannelSet := func(channelMap channels.ChannelMap) []string {
		var result []string
		for ch, _ := range channelMap {
			if availableChannels == nil || availableChannels.Contains(ch) {
				result = append(result, ch)
			}
		}
		return result
	}

	// Subroutine that writes a response entry for a document:
	totalRows := 0
	writeDoc := func(doc db.IDAndRev, channels []string) error {
		type allDocsRowValue struct {
			Rev      string              `json:"rev"`
			Channels []string            `json:"channels,omitempty"`
			Access   map[string]base.Set `json:"access,omitempty"` // for admins only
		}
		type allDocsRow struct {
			ID        string          `json:"id"`
			Key       string          `json:"key"`
			Value     allDocsRowValue `json:"value"`
			Doc       db.Body         `json:"doc,omitempty"`
			UpdateSeq uint64          `json:"update_seq,omitempty"`
		}

		row := allDocsRow{ID: doc.DocID, Key: doc.DocID}

		// Filter channels to ones available to user, and bail out if inaccessible:
		if explicitDocIDs == nil {
			if channels = filterChannels(channels); channels == nil {
				return nil
			}
		}

		if explicitDocIDs != nil || includeDocs || includeAccess {
			// Fetch the document body and other metadata that lives with it:
			body, channelSet, access, roleAccess, err := h.db.GetRevAndChannels(doc.DocID, doc.RevID, includeRevs)
			if err != nil || body["_removed"] != nil {
				return nil
			}
			if explicitDocIDs != nil {
				if channels = filterChannelSet(channelSet); channels == nil {
					return nil
//.........这里部分代码省略.........
开发者ID:rajasaur,项目名称:sync_gateway,代码行数:101,代码来源:bulk_api.go


注:本文中的github.com/couchbaselabs/sync_gateway/channels.TimedSet.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。