micro-tests/server/http/handler/github.go

26 lines
647 B
Go
Raw Normal View History

2021-02-12 13:26:44 +03:00
package handler
import (
"context"
"net/http"
2021-02-12 13:26:44 +03:00
httpsrv "github.com/unistack-org/micro-server-http/v3"
pb "github.com/unistack-org/micro-tests/client/http/proto"
)
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 httpsrv.SetError(&pb.Error{Message: "name is not correct"})
2021-02-12 13:26:44 +03:00
}
rsp.Name = "Vasiliy Tolstov"
httpsrv.SetRspCode(ctx, http.StatusOK)
return nil
}