k3s/vendor/github.com/rancher/kine/pkg/server/limited.go

53 lines
1.1 KiB
Go
Raw Normal View History

2019-08-22 05:12:46 +00:00
package server
import (
"context"
"fmt"
2019-12-12 01:27:03 +00:00
"go.etcd.io/etcd/etcdserver/etcdserverpb"
2019-08-22 05:12:46 +00:00
)
type LimitedServer struct {
backend Backend
}
func (l *LimitedServer) Range(ctx context.Context, r *etcdserverpb.RangeRequest) (*RangeResponse, error) {
if len(r.RangeEnd) == 0 {
return l.get(ctx, r)
}
return l.list(ctx, r)
}
func txnHeader(rev int64) *etcdserverpb.ResponseHeader {
return &etcdserverpb.ResponseHeader{
Revision: rev,
}
}
func (l *LimitedServer) Txn(ctx context.Context, txn *etcdserverpb.TxnRequest) (*etcdserverpb.TxnResponse, error) {
if put := isCreate(txn); put != nil {
return l.create(ctx, put, txn)
}
if rev, key, ok := isDelete(txn); ok {
return l.delete(ctx, key, rev)
}
if rev, key, value, lease, ok := isUpdate(txn); ok {
return l.update(ctx, rev, key, value, lease)
}
if isCompact(txn) {
return l.compact(ctx)
}
return nil, fmt.Errorf("unsupported transaction: %v", txn)
}
type ResponseHeader struct {
Revision int64
}
type RangeResponse struct {
Header *etcdserverpb.ResponseHeader
Kvs []*KeyValue
More bool
Count int64
}