first commit
This commit is contained in:
@@ -0,0 +1,191 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.36.11
|
||||
// protoc v6.33.2
|
||||
// source: proto/pasien.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
unsafe "unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type GetPasienByNomrRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Nomr string `protobuf:"bytes,1,opt,name=nomr,proto3" json:"nomr,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *GetPasienByNomrRequest) Reset() {
|
||||
*x = GetPasienByNomrRequest{}
|
||||
mi := &file_proto_pasien_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GetPasienByNomrRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetPasienByNomrRequest) ProtoMessage() {}
|
||||
|
||||
func (x *GetPasienByNomrRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_pasien_proto_msgTypes[0]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetPasienByNomrRequest.ProtoReflect.Descriptor instead.
|
||||
func (*GetPasienByNomrRequest) Descriptor() ([]byte, []int) {
|
||||
return file_proto_pasien_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *GetPasienByNomrRequest) GetNomr() string {
|
||||
if x != nil {
|
||||
return x.Nomr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type Pasien struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Nomr string `protobuf:"bytes,1,opt,name=nomr,proto3" json:"nomr,omitempty"`
|
||||
Nama string `protobuf:"bytes,2,opt,name=nama,proto3" json:"nama,omitempty"`
|
||||
Umur int32 `protobuf:"varint,3,opt,name=umur,proto3" json:"umur,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *Pasien) Reset() {
|
||||
*x = Pasien{}
|
||||
mi := &file_proto_pasien_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *Pasien) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Pasien) ProtoMessage() {}
|
||||
|
||||
func (x *Pasien) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_proto_pasien_proto_msgTypes[1]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Pasien.ProtoReflect.Descriptor instead.
|
||||
func (*Pasien) Descriptor() ([]byte, []int) {
|
||||
return file_proto_pasien_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Pasien) GetNomr() string {
|
||||
if x != nil {
|
||||
return x.Nomr
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Pasien) GetNama() string {
|
||||
if x != nil {
|
||||
return x.Nama
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Pasien) GetUmur() int32 {
|
||||
if x != nil {
|
||||
return x.Umur
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_proto_pasien_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_proto_pasien_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x12proto/pasien.proto\x12\x06pasien\",\n" +
|
||||
"\x16GetPasienByNomrRequest\x12\x12\n" +
|
||||
"\x04nomr\x18\x01 \x01(\tR\x04nomr\"D\n" +
|
||||
"\x06Pasien\x12\x12\n" +
|
||||
"\x04nomr\x18\x01 \x01(\tR\x04nomr\x12\x12\n" +
|
||||
"\x04nama\x18\x02 \x01(\tR\x04nama\x12\x12\n" +
|
||||
"\x04umur\x18\x03 \x01(\x05R\x04umur2R\n" +
|
||||
"\rPasienService\x12A\n" +
|
||||
"\x0fGetPasienByNomr\x12\x1e.pasien.GetPasienByNomrRequest\x1a\x0e.pasien.PasienB!Z\x1fapi-service/internal/grpc/pb;pbb\x06proto3"
|
||||
|
||||
var (
|
||||
file_proto_pasien_proto_rawDescOnce sync.Once
|
||||
file_proto_pasien_proto_rawDescData []byte
|
||||
)
|
||||
|
||||
func file_proto_pasien_proto_rawDescGZIP() []byte {
|
||||
file_proto_pasien_proto_rawDescOnce.Do(func() {
|
||||
file_proto_pasien_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_proto_pasien_proto_rawDesc), len(file_proto_pasien_proto_rawDesc)))
|
||||
})
|
||||
return file_proto_pasien_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_proto_pasien_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_proto_pasien_proto_goTypes = []any{
|
||||
(*GetPasienByNomrRequest)(nil), // 0: pasien.GetPasienByNomrRequest
|
||||
(*Pasien)(nil), // 1: pasien.Pasien
|
||||
}
|
||||
var file_proto_pasien_proto_depIdxs = []int32{
|
||||
0, // 0: pasien.PasienService.GetPasienByNomr:input_type -> pasien.GetPasienByNomrRequest
|
||||
1, // 1: pasien.PasienService.GetPasienByNomr:output_type -> pasien.Pasien
|
||||
1, // [1:2] is the sub-list for method output_type
|
||||
0, // [0:1] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_proto_pasien_proto_init() }
|
||||
func file_proto_pasien_proto_init() {
|
||||
if File_proto_pasien_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_pasien_proto_rawDesc), len(file_proto_pasien_proto_rawDesc)),
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_proto_pasien_proto_goTypes,
|
||||
DependencyIndexes: file_proto_pasien_proto_depIdxs,
|
||||
MessageInfos: file_proto_pasien_proto_msgTypes,
|
||||
}.Build()
|
||||
File_proto_pasien_proto = out.File
|
||||
file_proto_pasien_proto_goTypes = nil
|
||||
file_proto_pasien_proto_depIdxs = nil
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.6.0
|
||||
// - protoc v6.33.2
|
||||
// source: proto/pasien.proto
|
||||
|
||||
package pb
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.64.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
PasienService_GetPasienByNomr_FullMethodName = "/pasien.PasienService/GetPasienByNomr"
|
||||
)
|
||||
|
||||
// PasienServiceClient is the client API for PasienService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type PasienServiceClient interface {
|
||||
GetPasienByNomr(ctx context.Context, in *GetPasienByNomrRequest, opts ...grpc.CallOption) (*Pasien, error)
|
||||
}
|
||||
|
||||
type pasienServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewPasienServiceClient(cc grpc.ClientConnInterface) PasienServiceClient {
|
||||
return &pasienServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *pasienServiceClient) GetPasienByNomr(ctx context.Context, in *GetPasienByNomrRequest, opts ...grpc.CallOption) (*Pasien, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Pasien)
|
||||
err := c.cc.Invoke(ctx, PasienService_GetPasienByNomr_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// PasienServiceServer is the server API for PasienService service.
|
||||
// All implementations must embed UnimplementedPasienServiceServer
|
||||
// for forward compatibility.
|
||||
type PasienServiceServer interface {
|
||||
GetPasienByNomr(context.Context, *GetPasienByNomrRequest) (*Pasien, error)
|
||||
mustEmbedUnimplementedPasienServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedPasienServiceServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedPasienServiceServer struct{}
|
||||
|
||||
func (UnimplementedPasienServiceServer) GetPasienByNomr(context.Context, *GetPasienByNomrRequest) (*Pasien, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetPasienByNomr not implemented")
|
||||
}
|
||||
func (UnimplementedPasienServiceServer) mustEmbedUnimplementedPasienServiceServer() {}
|
||||
func (UnimplementedPasienServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafePasienServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to PasienServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafePasienServiceServer interface {
|
||||
mustEmbedUnimplementedPasienServiceServer()
|
||||
}
|
||||
|
||||
func RegisterPasienServiceServer(s grpc.ServiceRegistrar, srv PasienServiceServer) {
|
||||
// If the following call panics, it indicates UnimplementedPasienServiceServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&PasienService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _PasienService_GetPasienByNomr_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetPasienByNomrRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(PasienServiceServer).GetPasienByNomr(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: PasienService_GetPasienByNomr_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(PasienServiceServer).GetPasienByNomr(ctx, req.(*GetPasienByNomrRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// PasienService_ServiceDesc is the grpc.ServiceDesc for PasienService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var PasienService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "pasien.PasienService",
|
||||
HandlerType: (*PasienServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetPasienByNomr",
|
||||
Handler: _PasienService_GetPasienByNomr_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "proto/pasien.proto",
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"api-service/internal/config"
|
||||
"api-service/internal/grpc/pb"
|
||||
pasienHandlers "api-service/internal/handlers/pasien"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func RunGRPCServer(cfg *config.Config, pasienHandler *pasienHandlers.PasienHandler) error {
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", cfg.GRPC.Port))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s := grpc.NewServer()
|
||||
pb.RegisterPasienServiceServer(s, NewPasienGRPCServer(pasienHandler))
|
||||
|
||||
log.Printf("gRPC server listening on :%d", cfg.GRPC.Port)
|
||||
return s.Serve(lis)
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"api-service/internal/grpc/pb"
|
||||
pasienHandlers "api-service/internal/handlers/pasien"
|
||||
)
|
||||
|
||||
type PasienGRPCServer struct {
|
||||
pb.UnimplementedPasienServiceServer
|
||||
handler *pasienHandlers.PasienHandler
|
||||
}
|
||||
|
||||
func NewPasienGRPCServer(handler *pasienHandlers.PasienHandler) *PasienGRPCServer {
|
||||
return &PasienGRPCServer{handler: handler}
|
||||
}
|
||||
|
||||
func (s *PasienGRPCServer) GetPasien(ctx context.Context, req *pb.GetPasienRequest) (*pb.GetPasienResponse, error) {
|
||||
// Di sini idealnya kamu panggil service langsung.
|
||||
// Contoh pseudo (sesuaikan dengan service asli kamu):
|
||||
list, err := s.handler.Service.GetPasien(ctx, int(req.Page), int(req.Limit))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := make([]*pb.Pasien, 0, len(list))
|
||||
for _, p := range list {
|
||||
out = &pb.Pasien{
|
||||
Nomr: p.Nomr,
|
||||
Nama: p.Nama,
|
||||
Umur: int32(p.Umur),
|
||||
}
|
||||
out = append(out, out)
|
||||
}
|
||||
|
||||
return &pb.GetPasienResponse{Data: out}, nil
|
||||
}
|
||||
|
||||
func (s *PasienGRPCServer) GetPasienByNomr(ctx context.Context, req *pb.GetPasienByNomrRequest) (*pb.Pasien, error) {
|
||||
p, err := s.handler.Service.GetByNomr(ctx, req.Nomr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.Pasien{
|
||||
Nomr: p.Nomr,
|
||||
Nama: p.Nama,
|
||||
Umur: int32(p.Umur),
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user