mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
53 lines
1.1 KiB
Go
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
|
|
}
|