huge refactor

This commit is contained in:
nquidox 2025-10-03 19:17:01 +03:00
parent 8d6c2b6687
commit 38829c0179
23 changed files with 544 additions and 141 deletions

19
proto/scrapper.proto Normal file
View file

@ -0,0 +1,19 @@
syntax = "proto3";
package surugayaScrapper;
option go_package = "./surugayaScrapper";
message Task{
string merch_uuid = 1;
string link = 2;
}
message Result{
string merch_uuid = 1;
int32 price = 2;
}
service SurugayaScrapper {
rpc ProcessTasks (stream Task) returns (stream Result);
}

View file

@ -0,0 +1,193 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.8
// protoc v6.32.0
// source: scrapper.proto
package surugayaScrapper
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 Task struct {
state protoimpl.MessageState `protogen:"open.v1"`
MerchUuid string `protobuf:"bytes,1,opt,name=merch_uuid,json=merchUuid,proto3" json:"merch_uuid,omitempty"`
Link string `protobuf:"bytes,2,opt,name=link,proto3" json:"link,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Task) Reset() {
*x = Task{}
mi := &file_scrapper_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Task) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Task) ProtoMessage() {}
func (x *Task) ProtoReflect() protoreflect.Message {
mi := &file_scrapper_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 Task.ProtoReflect.Descriptor instead.
func (*Task) Descriptor() ([]byte, []int) {
return file_scrapper_proto_rawDescGZIP(), []int{0}
}
func (x *Task) GetMerchUuid() string {
if x != nil {
return x.MerchUuid
}
return ""
}
func (x *Task) GetLink() string {
if x != nil {
return x.Link
}
return ""
}
type Result struct {
state protoimpl.MessageState `protogen:"open.v1"`
MerchUuid string `protobuf:"bytes,1,opt,name=merch_uuid,json=merchUuid,proto3" json:"merch_uuid,omitempty"`
Price int32 `protobuf:"varint,2,opt,name=price,proto3" json:"price,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Result) Reset() {
*x = Result{}
mi := &file_scrapper_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Result) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Result) ProtoMessage() {}
func (x *Result) ProtoReflect() protoreflect.Message {
mi := &file_scrapper_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 Result.ProtoReflect.Descriptor instead.
func (*Result) Descriptor() ([]byte, []int) {
return file_scrapper_proto_rawDescGZIP(), []int{1}
}
func (x *Result) GetMerchUuid() string {
if x != nil {
return x.MerchUuid
}
return ""
}
func (x *Result) GetPrice() int32 {
if x != nil {
return x.Price
}
return 0
}
var File_scrapper_proto protoreflect.FileDescriptor
const file_scrapper_proto_rawDesc = "" +
"\n" +
"\x0escrapper.proto\x12\x10surugayaScrapper\"9\n" +
"\x04Task\x12\x1d\n" +
"\n" +
"merch_uuid\x18\x01 \x01(\tR\tmerchUuid\x12\x12\n" +
"\x04link\x18\x02 \x01(\tR\x04link\"=\n" +
"\x06Result\x12\x1d\n" +
"\n" +
"merch_uuid\x18\x01 \x01(\tR\tmerchUuid\x12\x14\n" +
"\x05price\x18\x02 \x01(\x05R\x05price2X\n" +
"\x10SurugayaScrapper\x12D\n" +
"\fProcessTasks\x12\x16.surugayaScrapper.Task\x1a\x18.surugayaScrapper.Result(\x010\x01B\x14Z\x12./surugayaScrapperb\x06proto3"
var (
file_scrapper_proto_rawDescOnce sync.Once
file_scrapper_proto_rawDescData []byte
)
func file_scrapper_proto_rawDescGZIP() []byte {
file_scrapper_proto_rawDescOnce.Do(func() {
file_scrapper_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_scrapper_proto_rawDesc), len(file_scrapper_proto_rawDesc)))
})
return file_scrapper_proto_rawDescData
}
var file_scrapper_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_scrapper_proto_goTypes = []any{
(*Task)(nil), // 0: surugayaScrapper.Task
(*Result)(nil), // 1: surugayaScrapper.Result
}
var file_scrapper_proto_depIdxs = []int32{
0, // 0: surugayaScrapper.SurugayaScrapper.ProcessTasks:input_type -> surugayaScrapper.Task
1, // 1: surugayaScrapper.SurugayaScrapper.ProcessTasks:output_type -> surugayaScrapper.Result
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_scrapper_proto_init() }
func file_scrapper_proto_init() {
if File_scrapper_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_scrapper_proto_rawDesc), len(file_scrapper_proto_rawDesc)),
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_scrapper_proto_goTypes,
DependencyIndexes: file_scrapper_proto_depIdxs,
MessageInfos: file_scrapper_proto_msgTypes,
}.Build()
File_scrapper_proto = out.File
file_scrapper_proto_goTypes = nil
file_scrapper_proto_depIdxs = nil
}

View file

@ -0,0 +1,115 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v6.32.0
// source: scrapper.proto
package surugayaScrapper
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 (
SurugayaScrapper_ProcessTasks_FullMethodName = "/surugayaScrapper.SurugayaScrapper/ProcessTasks"
)
// SurugayaScrapperClient is the client API for SurugayaScrapper 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 SurugayaScrapperClient interface {
ProcessTasks(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Task, Result], error)
}
type surugayaScrapperClient struct {
cc grpc.ClientConnInterface
}
func NewSurugayaScrapperClient(cc grpc.ClientConnInterface) SurugayaScrapperClient {
return &surugayaScrapperClient{cc}
}
func (c *surugayaScrapperClient) ProcessTasks(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Task, Result], error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
stream, err := c.cc.NewStream(ctx, &SurugayaScrapper_ServiceDesc.Streams[0], SurugayaScrapper_ProcessTasks_FullMethodName, cOpts...)
if err != nil {
return nil, err
}
x := &grpc.GenericClientStream[Task, Result]{ClientStream: stream}
return x, nil
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type SurugayaScrapper_ProcessTasksClient = grpc.BidiStreamingClient[Task, Result]
// SurugayaScrapperServer is the server API for SurugayaScrapper service.
// All implementations must embed UnimplementedSurugayaScrapperServer
// for forward compatibility.
type SurugayaScrapperServer interface {
ProcessTasks(grpc.BidiStreamingServer[Task, Result]) error
mustEmbedUnimplementedSurugayaScrapperServer()
}
// UnimplementedSurugayaScrapperServer 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 UnimplementedSurugayaScrapperServer struct{}
func (UnimplementedSurugayaScrapperServer) ProcessTasks(grpc.BidiStreamingServer[Task, Result]) error {
return status.Errorf(codes.Unimplemented, "method ProcessTasks not implemented")
}
func (UnimplementedSurugayaScrapperServer) mustEmbedUnimplementedSurugayaScrapperServer() {}
func (UnimplementedSurugayaScrapperServer) testEmbeddedByValue() {}
// UnsafeSurugayaScrapperServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to SurugayaScrapperServer will
// result in compilation errors.
type UnsafeSurugayaScrapperServer interface {
mustEmbedUnimplementedSurugayaScrapperServer()
}
func RegisterSurugayaScrapperServer(s grpc.ServiceRegistrar, srv SurugayaScrapperServer) {
// If the following call pancis, it indicates UnimplementedSurugayaScrapperServer 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(&SurugayaScrapper_ServiceDesc, srv)
}
func _SurugayaScrapper_ProcessTasks_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(SurugayaScrapperServer).ProcessTasks(&grpc.GenericServerStream[Task, Result]{ServerStream: stream})
}
// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.
type SurugayaScrapper_ProcessTasksServer = grpc.BidiStreamingServer[Task, Result]
// SurugayaScrapper_ServiceDesc is the grpc.ServiceDesc for SurugayaScrapper service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var SurugayaScrapper_ServiceDesc = grpc.ServiceDesc{
ServiceName: "surugayaScrapper.SurugayaScrapper",
HandlerType: (*SurugayaScrapperServer)(nil),
Methods: []grpc.MethodDesc{},
Streams: []grpc.StreamDesc{
{
StreamName: "ProcessTasks",
Handler: _SurugayaScrapper_ProcessTasks_Handler,
ServerStreams: true,
ClientStreams: true,
},
},
Metadata: "scrapper.proto",
}

View file

@ -14,7 +14,7 @@ message Task{
message Result{
string merch_uuid = 1;
string origin_name = 2;
uint32 price = 3;
int32 price = 3;
}
message ProcessorStatusRequest{}
@ -38,4 +38,4 @@ service TaskProcessor {
rpc RequestTask(google.protobuf.Empty) returns (stream Task);
rpc SendResult(stream Result) returns (google.protobuf.Empty);
rpc ProcessorStatus(ProcessorStatusRequest) returns (ProcessorStatusResponse);
}
}

View file

@ -86,7 +86,7 @@ type Result struct {
state protoimpl.MessageState `protogen:"open.v1"`
MerchUuid string `protobuf:"bytes,1,opt,name=merch_uuid,json=merchUuid,proto3" json:"merch_uuid,omitempty"`
OriginName string `protobuf:"bytes,2,opt,name=origin_name,json=originName,proto3" json:"origin_name,omitempty"`
Price uint32 `protobuf:"varint,3,opt,name=price,proto3" json:"price,omitempty"`
Price int32 `protobuf:"varint,3,opt,name=price,proto3" json:"price,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -135,7 +135,7 @@ func (x *Result) GetOriginName() string {
return ""
}
func (x *Result) GetPrice() uint32 {
func (x *Result) GetPrice() int32 {
if x != nil {
return x.Price
}
@ -326,7 +326,7 @@ const file_task_proto_rawDesc = "" +
"merch_uuid\x18\x01 \x01(\tR\tmerchUuid\x12\x1f\n" +
"\vorigin_name\x18\x02 \x01(\tR\n" +
"originName\x12\x14\n" +
"\x05price\x18\x03 \x01(\rR\x05price\"\x18\n" +
"\x05price\x18\x03 \x01(\x05R\x05price\"\x18\n" +
"\x16ProcessorStatusRequest\"\xc5\x03\n" +
"\x17ProcessorStatusResponse\x12\x1a\n" +
"\bappStart\x18\x01 \x01(\x03R\bappStart\x12\x1c\n" +