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