Skip to content

Commit

Permalink
feat: add comment(#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjcsjc123 committed Jul 4, 2023
1 parent c68863d commit ce85b5b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion engine/grpc/db.go → engine/grpc/service/db.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package grpc
package service

import (
"context"
"github.com/ByteStorage/FlyDB/engine"
"github.com/ByteStorage/FlyDB/lib/proto"
)

// Service is a grpc service for db
type Service struct {
proto.FlyDBServiceServer
db *engine.DB
}

// Put is a grpc service for put
func (s *Service) Put(ctx context.Context, req *proto.PutRequest) (*proto.PutResponse, error) {
err := s.db.Put([]byte(req.Key), []byte(req.Value))
if err != nil {
Expand All @@ -19,6 +21,7 @@ func (s *Service) Put(ctx context.Context, req *proto.PutRequest) (*proto.PutRes
return &proto.PutResponse{Ok: true}, nil
}

// Get is a grpc service for get
func (s *Service) Get(ctx context.Context, req *proto.GetRequest) (*proto.GetResponse, error) {
value, err := s.db.Get([]byte(req.Key))
if err != nil {
Expand All @@ -27,6 +30,7 @@ func (s *Service) Get(ctx context.Context, req *proto.GetRequest) (*proto.GetRes
return &proto.GetResponse{Value: string(value)}, nil
}

// Del is a grpc service for del
func (s *Service) Del(ctx context.Context, req *proto.DelRequest) (*proto.DelResponse, error) {
err := s.db.Delete([]byte(req.Key))
if err != nil {
Expand All @@ -35,6 +39,7 @@ func (s *Service) Del(ctx context.Context, req *proto.DelRequest) (*proto.DelRes
return &proto.DelResponse{Ok: true}, nil
}

// Keys is a grpc service for keys
func (s *Service) Keys(ctx context.Context, req *proto.KeysRequest) (*proto.KeysResponse, error) {
list := s.db.GetListKeys()
keys := make([]string, len(list))
Expand Down

0 comments on commit ce85b5b

Please sign in to comment.