in server/datasource/etcd/kv/kv_dao.go [213:235]
func (s *Dao) GetByKey(ctx context.Context, key, project, domain string, options ...datasource.FindOption) ([]*model.KVDoc, error) {
opts := datasource.FindOptions{Key: key}
for _, o := range options {
o(&opts)
}
kvs, err := s.listNoAuth(ctx, project, domain,
datasource.WithExactLabels(),
datasource.WithLabels(opts.Labels),
datasource.WithLabelFormat(opts.LabelFormat),
datasource.WithKey(key),
datasource.WithCaseSensitive())
if err != nil {
openlog.Error("check kv exist: " + err.Error())
return nil, err
}
if IsUniqueFind(opts) && len(kvs.Data) == 0 {
return nil, datasource.ErrKeyNotExists
}
if len(kvs.Data) != 1 {
return nil, datasource.ErrTooMany
}
return kvs.Data, nil
}