本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.Key.PrefixEnd方法的典型用法代码示例。如果您正苦于以下问题:Golang Key.PrefixEnd方法的具体用法?Golang Key.PrefixEnd怎么用?Golang Key.PrefixEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/proto.Key
的用法示例。
在下文中一共展示了Key.PrefixEnd方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getConfig
// getConfig retrieves the configuration for the specified key. If the
// key is empty, all configurations are returned. Otherwise, the
// leading "/" path delimiter is stripped and the configuration
// matching the remainder is retrieved. Note that this will retrieve
// the default config if "key" is equal to "/", and will list all
// configs if "key" is equal to "". The body result contains a listing
// of keys and retrieval of a config. The output format is determined
// by the request header.
func getConfig(db *client.DB, configPrefix proto.Key, config gogoproto.Message,
path string, r *http.Request) (body []byte, contentType string, err error) {
// Scan all configs if the key is empty.
if len(path) == 0 {
var rows []client.KeyValue
if rows, err = db.Scan(configPrefix, configPrefix.PrefixEnd(), maxGetResults); err != nil {
return
}
if len(rows) == maxGetResults {
log.Warningf("retrieved maximum number of results (%d); some may be missing", maxGetResults)
}
var prefixes []string
for _, row := range rows {
trimmed := bytes.TrimPrefix(row.Key, configPrefix)
prefixes = append(prefixes, url.QueryEscape(string(trimmed)))
}
// Encode the response.
body, contentType, err = util.MarshalResponse(r, prefixes, util.AllEncodings)
} else {
configkey := keys.MakeKey(configPrefix, proto.Key(path[1:]))
if err = db.GetProto(configkey, config); err != nil {
return
}
body, contentType, err = util.MarshalResponse(r, config, util.AllEncodings)
}
return
}
示例2: loadConfigMap
// loadConfigMap scans the config entries under keyPrefix and
// instantiates/returns a config map and its sha256 hash. Prefix
// configuration maps include accounting, permissions, and zones.
func loadConfigMap(eng engine.Engine, keyPrefix proto.Key, configI interface{}) (PrefixConfigMap, []byte, error) {
// TODO(tschottdorf): Currently this does not handle intents well.
kvs, _, err := engine.MVCCScan(eng, keyPrefix, keyPrefix.PrefixEnd(), 0, proto.MaxTimestamp, true /* consistent */, nil)
if err != nil {
return nil, nil, err
}
var configs []*PrefixConfig
sha := sha256.New()
for _, kv := range kvs {
// Instantiate an instance of the config type by unmarshalling
// proto encoded config from the Value into a new instance of configI.
config := reflect.New(reflect.TypeOf(configI)).Interface().(gogoproto.Message)
if err := gogoproto.Unmarshal(kv.Value.Bytes, config); err != nil {
return nil, nil, util.Errorf("unable to unmarshal config key %s: %s", string(kv.Key), err)
}
configs = append(configs, &PrefixConfig{Prefix: bytes.TrimPrefix(kv.Key, keyPrefix), Config: config})
sha.Write(kv.Value.Bytes)
}
m, err := NewPrefixConfigMap(configs)
return m, sha.Sum(nil), err
}