From 59dd91f65e0599fc5fee6e4eea0d265c1c1f2f81 Mon Sep 17 00:00:00 2001 From: Vladislav Dankevich Date: Fri, 12 Feb 2021 16:26:44 +0600 Subject: [PATCH] github handler --- server/http/handler/github.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 server/http/handler/github.go diff --git a/server/http/handler/github.go b/server/http/handler/github.go new file mode 100644 index 0000000..c0d259a --- /dev/null +++ b/server/http/handler/github.go @@ -0,0 +1,24 @@ +package handler + +import ( + "context" + httpsrv "github.com/unistack-org/micro-server-http/v3" + pb "github.com/unistack-org/micro-tests/client/http/proto" + "net/http" +) + +type GithubHandler struct{} + +func NewGithubHandler() *GithubHandler { + return &GithubHandler{} +} + +func (h *GithubHandler) LookupUser(ctx context.Context, req *pb.LookupUserReq, rsp *pb.LookupUserRsp) error { + if req.GetUsername() == "" || req.GetUsername() != "vtolstov" { + httpsrv.SetRspCode(ctx, http.StatusBadRequest) + return &pb.Error{Message: "name is not correct"} + } + rsp.Name = "Vasiliy Tolstov" + httpsrv.SetRspCode(ctx, http.StatusOK) + return nil +} -- 2.45.2