本文整理匯總了Golang中github.com/couchbase/sync_gateway/db.ChangesOptions.ActiveOnly方法的典型用法代碼示例。如果您正苦於以下問題:Golang ChangesOptions.ActiveOnly方法的具體用法?Golang ChangesOptions.ActiveOnly怎麽用?Golang ChangesOptions.ActiveOnly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/couchbase/sync_gateway/db.ChangesOptions
的用法示例。
在下文中一共展示了ChangesOptions.ActiveOnly方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleChanges
// Top-level handler for _changes feed requests. Accepts GET or POST requests.
func (h *handler) handleChanges() error {
// http://wiki.apache.org/couchdb/HTTP_database_API#Changes
// http://docs.couchdb.org/en/latest/api/database/changes.html
restExpvars.Add("changesFeeds_total", 1)
restExpvars.Add("changesFeeds_active", 1)
defer restExpvars.Add("changesFeeds_active", -1)
var feed string
var options db.ChangesOptions
var filter string
var channelsArray []string
var docIdsArray []string
if h.rq.Method == "GET" {
// GET request has parameters in URL:
feed = h.getQuery("feed")
var err error
if options.Since, err = h.db.ParseSequenceID(h.getJSONStringQuery("since")); err != nil {
return err
}
options.Limit = int(h.getIntQuery("limit", 0))
options.Conflicts = (h.getQuery("style") == "all_docs")
options.ActiveOnly = h.getBoolQuery("active_only")
options.IncludeDocs = (h.getBoolQuery("include_docs"))
filter = h.getQuery("filter")
channelsParam := h.getQuery("channels")
if channelsParam != "" {
channelsArray = strings.Split(channelsParam, ",")
}
docidsParam := h.getQuery("doc_ids")
if docidsParam != "" {
var docidKeys []string
err := json.Unmarshal([]byte(docidsParam), &docidKeys)
if err != nil {
err = base.HTTPErrorf(http.StatusBadRequest, "Bad doc id's")
}
if len(docidKeys) > 0 {
docIdsArray = docidKeys
}
}
options.HeartbeatMs = getRestrictedIntQuery(
h.rq.URL.Query(),
"heartbeat",
kDefaultHeartbeatMS,
kMinHeartbeatMS,
h.server.config.MaxHeartbeat*1000,
true,
)
options.TimeoutMs = getRestrictedIntQuery(
h.rq.URL.Query(),
"timeout",
kDefaultTimeoutMS,
0,
kMaxTimeoutMS,
true,
)
} else {
// POST request has parameters in JSON body:
body, err := h.readBody()
if err != nil {
return err
}
feed, options, filter, channelsArray, docIdsArray, _, err = h.readChangesOptionsFromJSON(body)
if err != nil {
return err
}
}
// Get the channels as parameters to an imaginary "bychannel" filter.
// The default is all channels the user can access.
userChannels := channels.SetOf(channels.AllChannelWildcard)
if filter != "" {
if filter == "sync_gateway/bychannel" {
if channelsArray == nil {
return base.HTTPErrorf(http.StatusBadRequest, "Missing 'channels' filter parameter")
}
var err error
userChannels, err = channels.SetFromArray(channelsArray, channels.ExpandStar)
if err != nil {
return err
}
if len(userChannels) == 0 {
return base.HTTPErrorf(http.StatusBadRequest, "Empty channel list")
}
} else if filter == "_doc_ids" {
if docIdsArray == nil {
return base.HTTPErrorf(http.StatusBadRequest, "Missing 'doc_ids' filter parameter")
}
if len(docIdsArray) == 0 {
return base.HTTPErrorf(http.StatusBadRequest, "Empty doc_ids list")
}
} else {
return base.HTTPErrorf(http.StatusBadRequest, "Unknown filter; try sync_gateway/bychannel or _doc_ids")
}
}
//.........這裏部分代碼省略.........
示例2: updateChangesOptionsFromQuery
func (h *handler) updateChangesOptionsFromQuery(feed *string, options *db.ChangesOptions, filter *string, channelsArray []string, docIdsArray []string) (newChannelsArray []string, newDocIdsArray []string, err error) {
if h.rq.URL.RawQuery == "" {
return channelsArray, docIdsArray, nil
}
values := h.rq.URL.Query()
if _, ok := values["feed"]; ok {
*feed = h.getQuery("feed")
}
if _, ok := values["since"]; ok {
if options.Since, err = h.db.ParseSequenceID(h.getJSONStringQuery("since")); err != nil {
return nil, nil, err
}
}
if _, ok := values["limit"]; ok {
options.Limit = int(h.getIntQuery("limit", 0))
}
if _, ok := values["style"]; ok {
options.Conflicts = (h.getQuery("style") == "all_docs")
}
if _, ok := values["active_only"]; ok {
options.ActiveOnly = h.getBoolQuery("active_only")
}
if _, ok := values["include_docs"]; ok {
options.IncludeDocs = (h.getBoolQuery("include_docs"))
}
if _, ok := values["filter"]; ok {
*filter = h.getQuery("filter")
}
if _, ok := values["channels"]; ok {
channelsParam := h.getQuery("channels")
if channelsParam != "" {
channelsArray = strings.Split(channelsParam, ",")
}
}
if _, ok := values["doc_ids"]; ok {
docidsParam := h.getQuery("doc_ids")
if docidsParam != "" {
var querydocidKeys []string
err := json.Unmarshal([]byte(docidsParam), &querydocidKeys)
if err == nil {
if len(querydocidKeys) > 0 {
docIdsArray = querydocidKeys
}
} else {
//This is not a JSON array so treat as a simple
//comma separated list of doc id's
docIdsArray = strings.Split(docidsParam, ",")
}
}
}
if _, ok := values["heartbeat"]; ok {
options.HeartbeatMs = getRestrictedIntQuery(
h.rq.URL.Query(),
"heartbeat",
kDefaultHeartbeatMS,
kMinHeartbeatMS,
h.server.config.MaxHeartbeat*1000,
true,
)
}
if _, ok := values["timeout"]; ok {
options.TimeoutMs = getRestrictedIntQuery(
h.rq.URL.Query(),
"timeout",
kDefaultTimeoutMS,
0,
kMaxTimeoutMS,
true,
)
}
return channelsArray, docIdsArray, nil
}