From 7f5cc85ef318e26566e0b4b82d81f9888427b8ca Mon Sep 17 00:00:00 2001 From: ajikamaludin Date: Fri, 15 Jul 2022 15:21:57 +0700 Subject: [PATCH] update readme --- api/v1/health/calldb.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 api/v1/health/calldb.go diff --git a/api/v1/health/calldb.go b/api/v1/health/calldb.go new file mode 100644 index 0000000..f9d9952 --- /dev/null +++ b/api/v1/health/calldb.go @@ -0,0 +1,39 @@ +package health + +import ( + "context" + "errors" + + "github.com/ajikamaludin/go-grpc_basic/pkg/v1/postgres" + "github.com/ajikamaludin/go-grpc_basic/pkg/v1/utils/constants" + hlpb "github.com/ajikamaludin/go-grpc_basic/proto/v1/health" + "github.com/golang/protobuf/ptypes/empty" +) + +func (s *Server) CallDb(ctx context.Context, req *empty.Empty) (*hlpb.Response, error) { + // select db + rows, err := s.config.Pg.CustomMainSelect(&postgres.CustomMain{}) + + if err != nil { + s.logger.Errorf("[HEALTH][GET] ERROR %v", err) + } + + if len(rows) <= 0 { + s.logger.Errorf("[HEALTH][GET] EMPTY ROW") + return nil, errors.New("Invoke empty rows") + } + var data []*hlpb.Data + for _, v := range rows { + data = append(data, &hlpb.Data{ + Email: v.UserId, + Username: v.Pass, + }) + } + + return &hlpb.Response{ + Success: true, + Code: constants.SuccessCode, + Desc: constants.SuccesDesc, + Data: data, + }, nil +}