k3s/vendor/github.com/rancher/kine/pkg/server/limited.go
Darren Shepherd a005219c5b Update vendor
2019-08-22 09:14:47 -07:00

53 lines
1.1 KiB
Go

package server
import (
"context"
"fmt"
"github.com/coreos/etcd/etcdserver/etcdserverpb"
)
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
}