commit 706340e0a9177396a1fde1975d1751b9951d0f1b Author: bagas Date: Tue Dec 30 23:48:52 2025 +0700 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/gen/identifier.pb.go b/gen/identifier.pb.go new file mode 100644 index 0000000..eaf5677 --- /dev/null +++ b/gen/identifier.pb.go @@ -0,0 +1,188 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.11 +// protoc v6.33.2 +// source: identifier.proto + +package gen + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + 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 IdentifierRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *IdentifierRequest) Reset() { + *x = IdentifierRequest{} + mi := &file_identifier_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *IdentifierRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IdentifierRequest) ProtoMessage() {} + +func (x *IdentifierRequest) ProtoReflect() protoreflect.Message { + mi := &file_identifier_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 IdentifierRequest.ProtoReflect.Descriptor instead. +func (*IdentifierRequest) Descriptor() ([]byte, []int) { + return file_identifier_proto_rawDescGZIP(), []int{0} +} + +func (x *IdentifierRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type IdentifierResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Slug string `protobuf:"bytes,2,opt,name=slug,proto3" json:"slug,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *IdentifierResponse) Reset() { + *x = IdentifierResponse{} + mi := &file_identifier_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *IdentifierResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IdentifierResponse) ProtoMessage() {} + +func (x *IdentifierResponse) ProtoReflect() protoreflect.Message { + mi := &file_identifier_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 IdentifierResponse.ProtoReflect.Descriptor instead. +func (*IdentifierResponse) Descriptor() ([]byte, []int) { + return file_identifier_proto_rawDescGZIP(), []int{1} +} + +func (x *IdentifierResponse) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *IdentifierResponse) GetSlug() string { + if x != nil { + return x.Slug + } + return "" +} + +var File_identifier_proto protoreflect.FileDescriptor + +const file_identifier_proto_rawDesc = "" + + "\n" + + "\x10identifier.proto\x12\n" + + "identifier\x1a\x1bgoogle/protobuf/empty.proto\"#\n" + + "\x11IdentifierRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\tR\x02id\"8\n" + + "\x12IdentifierResponse\x12\x0e\n" + + "\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" + + "\x04slug\x18\x02 \x01(\tR\x04slug2\x92\x01\n" + + "\bIdentity\x12D\n" + + "\x03Get\x12\x1d.identifier.IdentifierRequest\x1a\x1e.identifier.IdentifierResponse\x12@\n" + + "\x06Create\x12\x16.google.protobuf.Empty\x1a\x1e.identifier.IdentifierResponseB\aZ\x05./genb\x06proto3" + +var ( + file_identifier_proto_rawDescOnce sync.Once + file_identifier_proto_rawDescData []byte +) + +func file_identifier_proto_rawDescGZIP() []byte { + file_identifier_proto_rawDescOnce.Do(func() { + file_identifier_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_identifier_proto_rawDesc), len(file_identifier_proto_rawDesc))) + }) + return file_identifier_proto_rawDescData +} + +var file_identifier_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_identifier_proto_goTypes = []any{ + (*IdentifierRequest)(nil), // 0: identifier.IdentifierRequest + (*IdentifierResponse)(nil), // 1: identifier.IdentifierResponse + (*emptypb.Empty)(nil), // 2: google.protobuf.Empty +} +var file_identifier_proto_depIdxs = []int32{ + 0, // 0: identifier.Identity.Get:input_type -> identifier.IdentifierRequest + 2, // 1: identifier.Identity.Create:input_type -> google.protobuf.Empty + 1, // 2: identifier.Identity.Get:output_type -> identifier.IdentifierResponse + 1, // 3: identifier.Identity.Create:output_type -> identifier.IdentifierResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] 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_identifier_proto_init() } +func file_identifier_proto_init() { + if File_identifier_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_identifier_proto_rawDesc), len(file_identifier_proto_rawDesc)), + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_identifier_proto_goTypes, + DependencyIndexes: file_identifier_proto_depIdxs, + MessageInfos: file_identifier_proto_msgTypes, + }.Build() + File_identifier_proto = out.File + file_identifier_proto_goTypes = nil + file_identifier_proto_depIdxs = nil +} diff --git a/gen/identifier_grpc.pb.go b/gen/identifier_grpc.pb.go new file mode 100644 index 0000000..6b0c2f7 --- /dev/null +++ b/gen/identifier_grpc.pb.go @@ -0,0 +1,160 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.6.0 +// - protoc v6.33.2 +// source: identifier.proto + +package gen + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// 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 ( + Identity_Get_FullMethodName = "/identifier.Identity/Get" + Identity_Create_FullMethodName = "/identifier.Identity/Create" +) + +// IdentityClient is the client API for Identity 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 IdentityClient interface { + Get(ctx context.Context, in *IdentifierRequest, opts ...grpc.CallOption) (*IdentifierResponse, error) + Create(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*IdentifierResponse, error) +} + +type identityClient struct { + cc grpc.ClientConnInterface +} + +func NewIdentityClient(cc grpc.ClientConnInterface) IdentityClient { + return &identityClient{cc} +} + +func (c *identityClient) Get(ctx context.Context, in *IdentifierRequest, opts ...grpc.CallOption) (*IdentifierResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(IdentifierResponse) + err := c.cc.Invoke(ctx, Identity_Get_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *identityClient) Create(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*IdentifierResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(IdentifierResponse) + err := c.cc.Invoke(ctx, Identity_Create_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// IdentityServer is the server API for Identity service. +// All implementations must embed UnimplementedIdentityServer +// for forward compatibility. +type IdentityServer interface { + Get(context.Context, *IdentifierRequest) (*IdentifierResponse, error) + Create(context.Context, *emptypb.Empty) (*IdentifierResponse, error) + mustEmbedUnimplementedIdentityServer() +} + +// UnimplementedIdentityServer 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 UnimplementedIdentityServer struct{} + +func (UnimplementedIdentityServer) Get(context.Context, *IdentifierRequest) (*IdentifierResponse, error) { + return nil, status.Error(codes.Unimplemented, "method Get not implemented") +} +func (UnimplementedIdentityServer) Create(context.Context, *emptypb.Empty) (*IdentifierResponse, error) { + return nil, status.Error(codes.Unimplemented, "method Create not implemented") +} +func (UnimplementedIdentityServer) mustEmbedUnimplementedIdentityServer() {} +func (UnimplementedIdentityServer) testEmbeddedByValue() {} + +// UnsafeIdentityServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to IdentityServer will +// result in compilation errors. +type UnsafeIdentityServer interface { + mustEmbedUnimplementedIdentityServer() +} + +func RegisterIdentityServer(s grpc.ServiceRegistrar, srv IdentityServer) { + // If the following call panics, it indicates UnimplementedIdentityServer 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(&Identity_ServiceDesc, srv) +} + +func _Identity_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(IdentifierRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(IdentityServer).Get(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Identity_Get_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(IdentityServer).Get(ctx, req.(*IdentifierRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Identity_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(IdentityServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Identity_Create_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(IdentityServer).Create(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + +// Identity_ServiceDesc is the grpc.ServiceDesc for Identity service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Identity_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "identifier.Identity", + HandlerType: (*IdentityServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Get", + Handler: _Identity_Get_Handler, + }, + { + MethodName: "Create", + Handler: _Identity_Create_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "identifier.proto", +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4d888e8 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module git.fossy.my.id/bagas/tunnel-please-grpc + +go 1.25.5 + +require ( + google.golang.org/grpc v1.78.0 + google.golang.org/protobuf v1.36.11 +) + +require ( + golang.org/x/net v0.47.0 // indirect + golang.org/x/sys v0.38.0 // indirect + golang.org/x/text v0.31.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20251029180050-ab9386a59fda // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f165e8b --- /dev/null +++ b/go.sum @@ -0,0 +1,36 @@ +github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= +github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= +go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8= +go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM= +go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA= +go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI= +go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E= +go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg= +go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM= +go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA= +go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE= +go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs= +golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= +golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= +golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= +golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= +golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= +gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= +gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= +google.golang.org/genproto/googleapis/rpc v0.0.0-20251029180050-ab9386a59fda h1:i/Q+bfisr7gq6feoJnS/DlpdwEL4ihp41fvRiM3Ork0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20251029180050-ab9386a59fda/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk= +google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc= +google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U= +google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= +google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= diff --git a/proto/identifier.proto b/proto/identifier.proto new file mode 100644 index 0000000..eeaae91 --- /dev/null +++ b/proto/identifier.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package identifier; + +option go_package = "./gen"; + +import "google/protobuf/empty.proto"; + +service Identity { + rpc Get(IdentifierRequest) returns (IdentifierResponse); + rpc Create(google.protobuf.Empty) returns (IdentifierResponse); +} + +message IdentifierRequest { + string id = 1; +} + +message IdentifierResponse { + string id = 1; + string slug = 2; +} \ No newline at end of file