search coming soon

This commit is contained in:
Asim Aslam
2021-12-02 08:23:41 +00:00
parent c810ff45bc
commit d616d9098d
13 changed files with 464 additions and 0 deletions

50
search/handler/search.go Normal file
View File

@@ -0,0 +1,50 @@
package handler
import (
"context"
"sync"
"time"
"github.com/micro/services/pkg/tenant"
"github.com/micro/micro/v3/service/store"
pb "github.com/micro/services/search/proto"
)
type Search struct{}
var (
mtx sync.RWMutex
voteKey = "votes/"
)
type Vote struct {
Id string `json:"id"`
Message string `json:"message"`
VotedAt time.Time `json:"voted_at"`
}
func (n *Search) Vote(ctx context.Context, req *pb.VoteRequest, rsp *pb.VoteResponse) error {
mtx.Lock()
defer mtx.Unlock()
id, ok := tenant.FromContext(ctx)
if !ok {
id = "micro"
}
rec := store.NewRecord(voteKey + id, &Vote{
Id: id,
Message: req.Message,
VotedAt: time.Now(),
})
// we don't need to check the error
store.Write(rec)
rsp.Message = "Thanks for the vote!"
return nil
}