From 6e75f692633be21c1efd55f22bf8ed2d6928e105 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 15 Mar 2025 12:40:58 +0800 Subject: [PATCH] :sparkles: Feed provider SDK --- pkg/proto/feed.pb.go | 262 ++++++++++++++++++++++++++++++++++++++ pkg/proto/feed.proto | 24 ++++ pkg/proto/feed_grpc.pb.go | 121 ++++++++++++++++++ 3 files changed, 407 insertions(+) create mode 100644 pkg/proto/feed.pb.go create mode 100644 pkg/proto/feed.proto create mode 100644 pkg/proto/feed_grpc.pb.go diff --git a/pkg/proto/feed.pb.go b/pkg/proto/feed.pb.go new file mode 100644 index 0000000..b132b8c --- /dev/null +++ b/pkg/proto/feed.pb.go @@ -0,0 +1,262 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.35.1 +// protoc v5.28.3 +// source: feed.proto + +package proto + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +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 FeedItem struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + CreatedAt uint64 `protobuf:"varint,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + Content []byte `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` +} + +func (x *FeedItem) Reset() { + *x = FeedItem{} + mi := &file_feed_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FeedItem) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FeedItem) ProtoMessage() {} + +func (x *FeedItem) ProtoReflect() protoreflect.Message { + mi := &file_feed_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 FeedItem.ProtoReflect.Descriptor instead. +func (*FeedItem) Descriptor() ([]byte, []int) { + return file_feed_proto_rawDescGZIP(), []int{0} +} + +func (x *FeedItem) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +func (x *FeedItem) GetCreatedAt() uint64 { + if x != nil { + return x.CreatedAt + } + return 0 +} + +func (x *FeedItem) GetContent() []byte { + if x != nil { + return x.Content + } + return nil +} + +type GetFeedRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Limit int64 `protobuf:"varint,1,opt,name=limit,proto3" json:"limit,omitempty"` + Cursor *uint64 `protobuf:"varint,2,opt,name=cursor,proto3,oneof" json:"cursor,omitempty"` +} + +func (x *GetFeedRequest) Reset() { + *x = GetFeedRequest{} + mi := &file_feed_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetFeedRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetFeedRequest) ProtoMessage() {} + +func (x *GetFeedRequest) ProtoReflect() protoreflect.Message { + mi := &file_feed_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 GetFeedRequest.ProtoReflect.Descriptor instead. +func (*GetFeedRequest) Descriptor() ([]byte, []int) { + return file_feed_proto_rawDescGZIP(), []int{1} +} + +func (x *GetFeedRequest) GetLimit() int64 { + if x != nil { + return x.Limit + } + return 0 +} + +func (x *GetFeedRequest) GetCursor() uint64 { + if x != nil && x.Cursor != nil { + return *x.Cursor + } + return 0 +} + +type GetFeedResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Items []*FeedItem `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` +} + +func (x *GetFeedResponse) Reset() { + *x = GetFeedResponse{} + mi := &file_feed_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetFeedResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetFeedResponse) ProtoMessage() {} + +func (x *GetFeedResponse) ProtoReflect() protoreflect.Message { + mi := &file_feed_proto_msgTypes[2] + 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 GetFeedResponse.ProtoReflect.Descriptor instead. +func (*GetFeedResponse) Descriptor() ([]byte, []int) { + return file_feed_proto_rawDescGZIP(), []int{2} +} + +func (x *GetFeedResponse) GetItems() []*FeedItem { + if x != nil { + return x.Items + } + return nil +} + +var File_feed_proto protoreflect.FileDescriptor + +var file_feed_proto_rawDesc = []byte{ + 0x0a, 0x0a, 0x66, 0x65, 0x65, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x57, 0x0a, 0x08, 0x46, 0x65, 0x65, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x12, + 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, + 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x41, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x4e, 0x0a, 0x0e, + 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, + 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x6c, + 0x69, 0x6d, 0x69, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x04, 0x48, 0x00, 0x52, 0x06, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x88, 0x01, + 0x01, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x63, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x22, 0x38, 0x0a, 0x0f, + 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x25, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0f, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x46, 0x65, 0x65, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x52, + 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x32, 0x47, 0x0a, 0x0b, 0x46, 0x65, 0x65, 0x64, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x38, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, + 0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, + 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, + 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +} + +var ( + file_feed_proto_rawDescOnce sync.Once + file_feed_proto_rawDescData = file_feed_proto_rawDesc +) + +func file_feed_proto_rawDescGZIP() []byte { + file_feed_proto_rawDescOnce.Do(func() { + file_feed_proto_rawDescData = protoimpl.X.CompressGZIP(file_feed_proto_rawDescData) + }) + return file_feed_proto_rawDescData +} + +var file_feed_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_feed_proto_goTypes = []any{ + (*FeedItem)(nil), // 0: proto.FeedItem + (*GetFeedRequest)(nil), // 1: proto.GetFeedRequest + (*GetFeedResponse)(nil), // 2: proto.GetFeedResponse +} +var file_feed_proto_depIdxs = []int32{ + 0, // 0: proto.GetFeedResponse.items:type_name -> proto.FeedItem + 1, // 1: proto.FeedService.GetFeed:input_type -> proto.GetFeedRequest + 2, // 2: proto.FeedService.GetFeed:output_type -> proto.GetFeedResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_feed_proto_init() } +func file_feed_proto_init() { + if File_feed_proto != nil { + return + } + file_feed_proto_msgTypes[1].OneofWrappers = []any{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_feed_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_feed_proto_goTypes, + DependencyIndexes: file_feed_proto_depIdxs, + MessageInfos: file_feed_proto_msgTypes, + }.Build() + File_feed_proto = out.File + file_feed_proto_rawDesc = nil + file_feed_proto_goTypes = nil + file_feed_proto_depIdxs = nil +} diff --git a/pkg/proto/feed.proto b/pkg/proto/feed.proto new file mode 100644 index 0000000..ffd7330 --- /dev/null +++ b/pkg/proto/feed.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +option go_package = ".;proto"; + +package proto; + +service FeedService { + rpc GetFeed(GetFeedRequest) returns (GetFeedResponse); +} + +message FeedItem { + string type = 1; + uint64 created_at = 2; + bytes content = 3; +} + +message GetFeedRequest { + int64 limit = 1; + optional uint64 cursor = 2; +} + +message GetFeedResponse { + repeated FeedItem items = 1; +} diff --git a/pkg/proto/feed_grpc.pb.go b/pkg/proto/feed_grpc.pb.go new file mode 100644 index 0000000..eb1ebef --- /dev/null +++ b/pkg/proto/feed_grpc.pb.go @@ -0,0 +1,121 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.28.3 +// source: feed.proto + +package proto + +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 ( + FeedService_GetFeed_FullMethodName = "/proto.FeedService/GetFeed" +) + +// FeedServiceClient is the client API for FeedService 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 FeedServiceClient interface { + GetFeed(ctx context.Context, in *GetFeedRequest, opts ...grpc.CallOption) (*GetFeedResponse, error) +} + +type feedServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewFeedServiceClient(cc grpc.ClientConnInterface) FeedServiceClient { + return &feedServiceClient{cc} +} + +func (c *feedServiceClient) GetFeed(ctx context.Context, in *GetFeedRequest, opts ...grpc.CallOption) (*GetFeedResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetFeedResponse) + err := c.cc.Invoke(ctx, FeedService_GetFeed_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// FeedServiceServer is the server API for FeedService service. +// All implementations must embed UnimplementedFeedServiceServer +// for forward compatibility. +type FeedServiceServer interface { + GetFeed(context.Context, *GetFeedRequest) (*GetFeedResponse, error) + mustEmbedUnimplementedFeedServiceServer() +} + +// UnimplementedFeedServiceServer 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 UnimplementedFeedServiceServer struct{} + +func (UnimplementedFeedServiceServer) GetFeed(context.Context, *GetFeedRequest) (*GetFeedResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetFeed not implemented") +} +func (UnimplementedFeedServiceServer) mustEmbedUnimplementedFeedServiceServer() {} +func (UnimplementedFeedServiceServer) testEmbeddedByValue() {} + +// UnsafeFeedServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to FeedServiceServer will +// result in compilation errors. +type UnsafeFeedServiceServer interface { + mustEmbedUnimplementedFeedServiceServer() +} + +func RegisterFeedServiceServer(s grpc.ServiceRegistrar, srv FeedServiceServer) { + // If the following call pancis, it indicates UnimplementedFeedServiceServer 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(&FeedService_ServiceDesc, srv) +} + +func _FeedService_GetFeed_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetFeedRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(FeedServiceServer).GetFeed(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: FeedService_GetFeed_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FeedServiceServer).GetFeed(ctx, req.(*GetFeedRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// FeedService_ServiceDesc is the grpc.ServiceDesc for FeedService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var FeedService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "proto.FeedService", + HandlerType: (*FeedServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetFeed", + Handler: _FeedService_GetFeed_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "feed.proto", +}