mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-25 18:27:54 +08:00
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
|
package weed_server
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
||
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||
|
)
|
||
|
|
||
|
func (fs *FilerServer) KvGet(ctx context.Context, req *filer_pb.KvGetRequest) (*filer_pb.KvGetResponse, error) {
|
||
|
|
||
|
value, err := fs.filer.Store.KvGet(ctx, req.Key)
|
||
|
if err == filer.ErrKvNotFound {
|
||
|
return &filer_pb.KvGetResponse{}, nil
|
||
|
}
|
||
|
|
||
|
if err != nil {
|
||
|
return &filer_pb.KvGetResponse{Error: err.Error()}, nil
|
||
|
}
|
||
|
|
||
|
return &filer_pb.KvGetResponse{
|
||
|
Value: value,
|
||
|
}, nil
|
||
|
|
||
|
}
|
||
|
|
||
|
// KvPut sets the key~value. if empty value, delete the kv entry
|
||
|
func (fs *FilerServer) KvPut(ctx context.Context, req *filer_pb.KvPutRequest) (*filer_pb.KvPutResponse, error) {
|
||
|
|
||
|
if len(req.Value) == 0 {
|
||
|
if err := fs.filer.Store.KvDelete(ctx, req.Key); err != nil {
|
||
|
return &filer_pb.KvPutResponse{Error: err.Error()}, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
err := fs.filer.Store.KvPut(ctx, req.Key, req.Value)
|
||
|
if err != nil {
|
||
|
return &filer_pb.KvPutResponse{Error: err.Error()}, nil
|
||
|
}
|
||
|
|
||
|
return &filer_pb.KvPutResponse{}, nil
|
||
|
|
||
|
}
|