本文整理匯總了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
}