diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6abdda8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "protoc": { + "options": [ + "--proto_path=D:/Code/chabo-api" + ] + } +} \ No newline at end of file diff --git a/go.mod b/go.mod index 564f0fc..5bb7368 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( ) require ( + github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/montanaflynn/stats v0.7.1 // indirect @@ -18,6 +19,7 @@ require ( github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect golang.org/x/sync v0.3.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect ) require ( @@ -54,6 +56,7 @@ require ( golang.org/x/sys v0.10.0 // indirect golang.org/x/text v0.11.0 // indirect golang.org/x/tools v0.11.0 // indirect + google.golang.org/grpc v1.58.0 google.golang.org/protobuf v1.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 4a22b7a..3aaeafc 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM= github.com/bytedance/sonic v1.9.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= @@ -45,6 +47,8 @@ github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QX github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -90,6 +94,7 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0= github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -181,7 +186,12 @@ golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= +google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= +google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/grpc/v1/boat.proto b/grpc/v1/boat.proto new file mode 100644 index 0000000..5de1583 --- /dev/null +++ b/grpc/v1/boat.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; +option go_package = "/internal/generate"; + +package grpc.v1; + +enum BoatManeuver { + leaving = 0; + entering = 1; +} + +message Timestamp { + int64 seconds = 1; + int32 nanos = 2; +} + +message Boat { + string name = 1; + BoatManeuver maneuver = 2; + Timestamp approximativeCrossingDate = 3; +} + +message BoatNameRequest { string name = 1; } + +message Boats { repeated Boat forecasts = 1; } + +service BoatService { + rpc GetBoat(BoatNameRequest) returns (Boat) {} +} diff --git a/grpc/v1/forecast.proto b/grpc/v1/forecast.proto new file mode 100644 index 0000000..79f0631 --- /dev/null +++ b/grpc/v1/forecast.proto @@ -0,0 +1,49 @@ +syntax = "proto3"; +option go_package = "/internal/generate"; + +package grpc.v1; + +import "grpc/v1/boat.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/empty.proto"; + +enum ClosingType { + twoWay = 0; + oneWay = 1; +} + +enum ClosingReason { + boatCrossing = 0; + maintenance = 1; +} + +message ForecastIDQuery { string ID = 1; } + +message ForecastQuery { + string timezone = 1; + int32 offset = 2; + int32 limit = 3; + string from = 4; + string boat = 5; + string maneuver = 6; + string reason = 7; +} + +message Forecast { + string ID = 1; + ClosingType closingType = 2; + ClosingReason closingReason = 3; + google.protobuf.Duration closingDuration = 4; + google.protobuf.Timestamp circulationClosingDate = 5; + google.protobuf.Timestamp circulationReopeningDate = 6; + repeated grpc.v1.Boats boats = 7; +} + +message Forecasts { repeated Forecast forecasts = 1; } + +service ForecastService { + rpc GetForcast(ForecastIDQuery) returns (Forecast); + rpc GetForcasts(ForecastQuery) returns (Forecasts); + rpc GetAllForcasts(google.protobuf.Empty) returns (Forecasts); +} diff --git a/grpc/v1/healthcheck.proto b/grpc/v1/healthcheck.proto new file mode 100644 index 0000000..70ed5f9 --- /dev/null +++ b/grpc/v1/healthcheck.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +option go_package = "/internal/generate"; + +package grpc.v1; + +message Empty {} + +message HealthCheckResponse { + enum ServingStatus { + UNKNOWN = 0; + SERVING = 1; + NOT_SERVING = 2; + } + ServingStatus status = 1; + string info = 2; +} + +service HealthCheckService { + rpc CheckHealth(Empty) returns (HealthCheckResponse); + rpc WatchHealth(Empty) returns (stream HealthCheckResponse); +} \ No newline at end of file diff --git a/grpc/v1/refresh_event.proto b/grpc/v1/refresh_event.proto new file mode 100644 index 0000000..2861a72 --- /dev/null +++ b/grpc/v1/refresh_event.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; +option go_package = "/internal/generate"; + +package grpc.v1; + +import "google/protobuf/empty.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/timestamp.proto"; + + +message RefreshResponse { + string ID = 1; + int32 itemCount = 2; + google.protobuf.Duration duration = 3; + google.protobuf.Timestamp timestamp = 4; + +} + +service RefreshResponseService { + rpc GetLastRefresh(google.protobuf.Empty) returns (RefreshResponse); +} \ No newline at end of file diff --git a/internal/generate/boat.pb.go b/internal/generate/boat.pb.go new file mode 100644 index 0000000..7032ecc --- /dev/null +++ b/internal/generate/boat.pb.go @@ -0,0 +1,425 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v4.24.3 +// source: grpc/v1/boat.proto + +package generate + +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 BoatManeuver int32 + +const ( + BoatManeuver_leaving BoatManeuver = 0 + BoatManeuver_entering BoatManeuver = 1 +) + +// Enum value maps for BoatManeuver. +var ( + BoatManeuver_name = map[int32]string{ + 0: "leaving", + 1: "entering", + } + BoatManeuver_value = map[string]int32{ + "leaving": 0, + "entering": 1, + } +) + +func (x BoatManeuver) Enum() *BoatManeuver { + p := new(BoatManeuver) + *p = x + return p +} + +func (x BoatManeuver) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (BoatManeuver) Descriptor() protoreflect.EnumDescriptor { + return file_grpc_v1_boat_proto_enumTypes[0].Descriptor() +} + +func (BoatManeuver) Type() protoreflect.EnumType { + return &file_grpc_v1_boat_proto_enumTypes[0] +} + +func (x BoatManeuver) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use BoatManeuver.Descriptor instead. +func (BoatManeuver) EnumDescriptor() ([]byte, []int) { + return file_grpc_v1_boat_proto_rawDescGZIP(), []int{0} +} + +type Timestamp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"` + Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"` +} + +func (x *Timestamp) Reset() { + *x = Timestamp{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_boat_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Timestamp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Timestamp) ProtoMessage() {} + +func (x *Timestamp) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_boat_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Timestamp.ProtoReflect.Descriptor instead. +func (*Timestamp) Descriptor() ([]byte, []int) { + return file_grpc_v1_boat_proto_rawDescGZIP(), []int{0} +} + +func (x *Timestamp) GetSeconds() int64 { + if x != nil { + return x.Seconds + } + return 0 +} + +func (x *Timestamp) GetNanos() int32 { + if x != nil { + return x.Nanos + } + return 0 +} + +type Boat struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Maneuver BoatManeuver `protobuf:"varint,2,opt,name=maneuver,proto3,enum=grpc.v1.BoatManeuver" json:"maneuver,omitempty"` + ApproximativeCrossingDate *Timestamp `protobuf:"bytes,3,opt,name=approximativeCrossingDate,proto3" json:"approximativeCrossingDate,omitempty"` +} + +func (x *Boat) Reset() { + *x = Boat{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_boat_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Boat) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Boat) ProtoMessage() {} + +func (x *Boat) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_boat_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Boat.ProtoReflect.Descriptor instead. +func (*Boat) Descriptor() ([]byte, []int) { + return file_grpc_v1_boat_proto_rawDescGZIP(), []int{1} +} + +func (x *Boat) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Boat) GetManeuver() BoatManeuver { + if x != nil { + return x.Maneuver + } + return BoatManeuver_leaving +} + +func (x *Boat) GetApproximativeCrossingDate() *Timestamp { + if x != nil { + return x.ApproximativeCrossingDate + } + return nil +} + +type BoatNameRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *BoatNameRequest) Reset() { + *x = BoatNameRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_boat_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BoatNameRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BoatNameRequest) ProtoMessage() {} + +func (x *BoatNameRequest) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_boat_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BoatNameRequest.ProtoReflect.Descriptor instead. +func (*BoatNameRequest) Descriptor() ([]byte, []int) { + return file_grpc_v1_boat_proto_rawDescGZIP(), []int{2} +} + +func (x *BoatNameRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type Boats struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Forecasts []*Boat `protobuf:"bytes,1,rep,name=forecasts,proto3" json:"forecasts,omitempty"` +} + +func (x *Boats) Reset() { + *x = Boats{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_boat_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Boats) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Boats) ProtoMessage() {} + +func (x *Boats) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_boat_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Boats.ProtoReflect.Descriptor instead. +func (*Boats) Descriptor() ([]byte, []int) { + return file_grpc_v1_boat_proto_rawDescGZIP(), []int{3} +} + +func (x *Boats) GetForecasts() []*Boat { + if x != nil { + return x.Forecasts + } + return nil +} + +var File_grpc_v1_boat_proto protoreflect.FileDescriptor + +var file_grpc_v1_boat_proto_rawDesc = []byte{ + 0x0a, 0x12, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x76, 0x31, 0x2f, 0x62, 0x6f, 0x61, 0x74, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x22, 0x3b, 0x0a, + 0x09, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, + 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x73, 0x65, 0x63, + 0x6f, 0x6e, 0x64, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x6e, 0x61, 0x6e, 0x6f, 0x73, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x05, 0x6e, 0x61, 0x6e, 0x6f, 0x73, 0x22, 0x9f, 0x01, 0x0a, 0x04, 0x42, + 0x6f, 0x61, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x31, 0x0a, 0x08, 0x6d, 0x61, 0x6e, 0x65, 0x75, + 0x76, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x15, 0x2e, 0x67, 0x72, 0x70, 0x63, + 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x74, 0x4d, 0x61, 0x6e, 0x65, 0x75, 0x76, 0x65, 0x72, + 0x52, 0x08, 0x6d, 0x61, 0x6e, 0x65, 0x75, 0x76, 0x65, 0x72, 0x12, 0x50, 0x0a, 0x19, 0x61, 0x70, + 0x70, 0x72, 0x6f, 0x78, 0x69, 0x6d, 0x61, 0x74, 0x69, 0x76, 0x65, 0x43, 0x72, 0x6f, 0x73, 0x73, + 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, + 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x52, 0x19, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x78, 0x69, 0x6d, 0x61, 0x74, 0x69, 0x76, 0x65, + 0x43, 0x72, 0x6f, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x65, 0x22, 0x25, 0x0a, 0x0f, + 0x42, 0x6f, 0x61, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x22, 0x34, 0x0a, 0x05, 0x42, 0x6f, 0x61, 0x74, 0x73, 0x12, 0x2b, 0x0a, 0x09, + 0x66, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x0d, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x74, 0x52, 0x09, + 0x66, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x73, 0x2a, 0x29, 0x0a, 0x0c, 0x42, 0x6f, 0x61, + 0x74, 0x4d, 0x61, 0x6e, 0x65, 0x75, 0x76, 0x65, 0x72, 0x12, 0x0b, 0x0a, 0x07, 0x6c, 0x65, 0x61, + 0x76, 0x69, 0x6e, 0x67, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x69, + 0x6e, 0x67, 0x10, 0x01, 0x32, 0x43, 0x0a, 0x0b, 0x42, 0x6f, 0x61, 0x74, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x42, 0x6f, 0x61, 0x74, 0x12, 0x18, + 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x74, 0x4e, 0x61, 0x6d, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, + 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x74, 0x22, 0x00, 0x42, 0x14, 0x5a, 0x12, 0x2f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_grpc_v1_boat_proto_rawDescOnce sync.Once + file_grpc_v1_boat_proto_rawDescData = file_grpc_v1_boat_proto_rawDesc +) + +func file_grpc_v1_boat_proto_rawDescGZIP() []byte { + file_grpc_v1_boat_proto_rawDescOnce.Do(func() { + file_grpc_v1_boat_proto_rawDescData = protoimpl.X.CompressGZIP(file_grpc_v1_boat_proto_rawDescData) + }) + return file_grpc_v1_boat_proto_rawDescData +} + +var file_grpc_v1_boat_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_grpc_v1_boat_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_grpc_v1_boat_proto_goTypes = []interface{}{ + (BoatManeuver)(0), // 0: grpc.v1.BoatManeuver + (*Timestamp)(nil), // 1: grpc.v1.Timestamp + (*Boat)(nil), // 2: grpc.v1.Boat + (*BoatNameRequest)(nil), // 3: grpc.v1.BoatNameRequest + (*Boats)(nil), // 4: grpc.v1.Boats +} +var file_grpc_v1_boat_proto_depIdxs = []int32{ + 0, // 0: grpc.v1.Boat.maneuver:type_name -> grpc.v1.BoatManeuver + 1, // 1: grpc.v1.Boat.approximativeCrossingDate:type_name -> grpc.v1.Timestamp + 2, // 2: grpc.v1.Boats.forecasts:type_name -> grpc.v1.Boat + 3, // 3: grpc.v1.BoatService.GetBoat:input_type -> grpc.v1.BoatNameRequest + 2, // 4: grpc.v1.BoatService.GetBoat:output_type -> grpc.v1.Boat + 4, // [4:5] is the sub-list for method output_type + 3, // [3:4] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_grpc_v1_boat_proto_init() } +func file_grpc_v1_boat_proto_init() { + if File_grpc_v1_boat_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_grpc_v1_boat_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Timestamp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_v1_boat_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Boat); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_v1_boat_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BoatNameRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_v1_boat_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Boats); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_grpc_v1_boat_proto_rawDesc, + NumEnums: 1, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_grpc_v1_boat_proto_goTypes, + DependencyIndexes: file_grpc_v1_boat_proto_depIdxs, + EnumInfos: file_grpc_v1_boat_proto_enumTypes, + MessageInfos: file_grpc_v1_boat_proto_msgTypes, + }.Build() + File_grpc_v1_boat_proto = out.File + file_grpc_v1_boat_proto_rawDesc = nil + file_grpc_v1_boat_proto_goTypes = nil + file_grpc_v1_boat_proto_depIdxs = nil +} diff --git a/internal/generate/boat_grpc.pb.go b/internal/generate/boat_grpc.pb.go new file mode 100644 index 0000000..ea7b8b1 --- /dev/null +++ b/internal/generate/boat_grpc.pb.go @@ -0,0 +1,109 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.24.3 +// source: grpc/v1/boat.proto + +package generate + +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.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + BoatService_GetBoat_FullMethodName = "/grpc.v1.BoatService/GetBoat" +) + +// BoatServiceClient is the client API for BoatService 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 BoatServiceClient interface { + GetBoat(ctx context.Context, in *BoatNameRequest, opts ...grpc.CallOption) (*Boat, error) +} + +type boatServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewBoatServiceClient(cc grpc.ClientConnInterface) BoatServiceClient { + return &boatServiceClient{cc} +} + +func (c *boatServiceClient) GetBoat(ctx context.Context, in *BoatNameRequest, opts ...grpc.CallOption) (*Boat, error) { + out := new(Boat) + err := c.cc.Invoke(ctx, BoatService_GetBoat_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BoatServiceServer is the server API for BoatService service. +// All implementations must embed UnimplementedBoatServiceServer +// for forward compatibility +type BoatServiceServer interface { + GetBoat(context.Context, *BoatNameRequest) (*Boat, error) + mustEmbedUnimplementedBoatServiceServer() +} + +// UnimplementedBoatServiceServer must be embedded to have forward compatible implementations. +type UnimplementedBoatServiceServer struct { +} + +func (UnimplementedBoatServiceServer) GetBoat(context.Context, *BoatNameRequest) (*Boat, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetBoat not implemented") +} +func (UnimplementedBoatServiceServer) mustEmbedUnimplementedBoatServiceServer() {} + +// UnsafeBoatServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BoatServiceServer will +// result in compilation errors. +type UnsafeBoatServiceServer interface { + mustEmbedUnimplementedBoatServiceServer() +} + +func RegisterBoatServiceServer(s grpc.ServiceRegistrar, srv BoatServiceServer) { + s.RegisterService(&BoatService_ServiceDesc, srv) +} + +func _BoatService_GetBoat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BoatNameRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BoatServiceServer).GetBoat(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: BoatService_GetBoat_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BoatServiceServer).GetBoat(ctx, req.(*BoatNameRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// BoatService_ServiceDesc is the grpc.ServiceDesc for BoatService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var BoatService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "grpc.v1.BoatService", + HandlerType: (*BoatServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetBoat", + Handler: _BoatService_GetBoat_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "grpc/v1/boat.proto", +} diff --git a/internal/generate/forecast.pb.go b/internal/generate/forecast.pb.go new file mode 100644 index 0000000..b0a1404 --- /dev/null +++ b/internal/generate/forecast.pb.go @@ -0,0 +1,603 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v4.24.3 +// source: grpc/v1/forecast.proto + +package generate + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + durationpb "google.golang.org/protobuf/types/known/durationpb" + emptypb "google.golang.org/protobuf/types/known/emptypb" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + 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 ClosingType int32 + +const ( + ClosingType_twoWay ClosingType = 0 + ClosingType_oneWay ClosingType = 1 +) + +// Enum value maps for ClosingType. +var ( + ClosingType_name = map[int32]string{ + 0: "twoWay", + 1: "oneWay", + } + ClosingType_value = map[string]int32{ + "twoWay": 0, + "oneWay": 1, + } +) + +func (x ClosingType) Enum() *ClosingType { + p := new(ClosingType) + *p = x + return p +} + +func (x ClosingType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ClosingType) Descriptor() protoreflect.EnumDescriptor { + return file_grpc_v1_forecast_proto_enumTypes[0].Descriptor() +} + +func (ClosingType) Type() protoreflect.EnumType { + return &file_grpc_v1_forecast_proto_enumTypes[0] +} + +func (x ClosingType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ClosingType.Descriptor instead. +func (ClosingType) EnumDescriptor() ([]byte, []int) { + return file_grpc_v1_forecast_proto_rawDescGZIP(), []int{0} +} + +type ClosingReason int32 + +const ( + ClosingReason_boatCrossing ClosingReason = 0 + ClosingReason_maintenance ClosingReason = 1 +) + +// Enum value maps for ClosingReason. +var ( + ClosingReason_name = map[int32]string{ + 0: "boatCrossing", + 1: "maintenance", + } + ClosingReason_value = map[string]int32{ + "boatCrossing": 0, + "maintenance": 1, + } +) + +func (x ClosingReason) Enum() *ClosingReason { + p := new(ClosingReason) + *p = x + return p +} + +func (x ClosingReason) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (ClosingReason) Descriptor() protoreflect.EnumDescriptor { + return file_grpc_v1_forecast_proto_enumTypes[1].Descriptor() +} + +func (ClosingReason) Type() protoreflect.EnumType { + return &file_grpc_v1_forecast_proto_enumTypes[1] +} + +func (x ClosingReason) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use ClosingReason.Descriptor instead. +func (ClosingReason) EnumDescriptor() ([]byte, []int) { + return file_grpc_v1_forecast_proto_rawDescGZIP(), []int{1} +} + +type ForecastIDQuery struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` +} + +func (x *ForecastIDQuery) Reset() { + *x = ForecastIDQuery{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_forecast_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ForecastIDQuery) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForecastIDQuery) ProtoMessage() {} + +func (x *ForecastIDQuery) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_forecast_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ForecastIDQuery.ProtoReflect.Descriptor instead. +func (*ForecastIDQuery) Descriptor() ([]byte, []int) { + return file_grpc_v1_forecast_proto_rawDescGZIP(), []int{0} +} + +func (x *ForecastIDQuery) GetID() string { + if x != nil { + return x.ID + } + return "" +} + +type ForecastQuery struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Timezone string `protobuf:"bytes,1,opt,name=timezone,proto3" json:"timezone,omitempty"` + Offset int32 `protobuf:"varint,2,opt,name=offset,proto3" json:"offset,omitempty"` + Limit int32 `protobuf:"varint,3,opt,name=limit,proto3" json:"limit,omitempty"` + From string `protobuf:"bytes,4,opt,name=from,proto3" json:"from,omitempty"` + Boat string `protobuf:"bytes,5,opt,name=boat,proto3" json:"boat,omitempty"` + Maneuver string `protobuf:"bytes,6,opt,name=maneuver,proto3" json:"maneuver,omitempty"` + Reason string `protobuf:"bytes,7,opt,name=reason,proto3" json:"reason,omitempty"` +} + +func (x *ForecastQuery) Reset() { + *x = ForecastQuery{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_forecast_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ForecastQuery) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForecastQuery) ProtoMessage() {} + +func (x *ForecastQuery) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_forecast_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ForecastQuery.ProtoReflect.Descriptor instead. +func (*ForecastQuery) Descriptor() ([]byte, []int) { + return file_grpc_v1_forecast_proto_rawDescGZIP(), []int{1} +} + +func (x *ForecastQuery) GetTimezone() string { + if x != nil { + return x.Timezone + } + return "" +} + +func (x *ForecastQuery) GetOffset() int32 { + if x != nil { + return x.Offset + } + return 0 +} + +func (x *ForecastQuery) GetLimit() int32 { + if x != nil { + return x.Limit + } + return 0 +} + +func (x *ForecastQuery) GetFrom() string { + if x != nil { + return x.From + } + return "" +} + +func (x *ForecastQuery) GetBoat() string { + if x != nil { + return x.Boat + } + return "" +} + +func (x *ForecastQuery) GetManeuver() string { + if x != nil { + return x.Maneuver + } + return "" +} + +func (x *ForecastQuery) GetReason() string { + if x != nil { + return x.Reason + } + return "" +} + +type Forecast struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` + ClosingType ClosingType `protobuf:"varint,2,opt,name=closingType,proto3,enum=grpc.v1.ClosingType" json:"closingType,omitempty"` + ClosingReason ClosingReason `protobuf:"varint,3,opt,name=closingReason,proto3,enum=grpc.v1.ClosingReason" json:"closingReason,omitempty"` + ClosingDuration *durationpb.Duration `protobuf:"bytes,4,opt,name=closingDuration,proto3" json:"closingDuration,omitempty"` + CirculationClosingDate *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=circulationClosingDate,proto3" json:"circulationClosingDate,omitempty"` + CirculationReopeningDate *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=circulationReopeningDate,proto3" json:"circulationReopeningDate,omitempty"` + Boats []*Boats `protobuf:"bytes,7,rep,name=boats,proto3" json:"boats,omitempty"` +} + +func (x *Forecast) Reset() { + *x = Forecast{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_forecast_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Forecast) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Forecast) ProtoMessage() {} + +func (x *Forecast) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_forecast_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Forecast.ProtoReflect.Descriptor instead. +func (*Forecast) Descriptor() ([]byte, []int) { + return file_grpc_v1_forecast_proto_rawDescGZIP(), []int{2} +} + +func (x *Forecast) GetID() string { + if x != nil { + return x.ID + } + return "" +} + +func (x *Forecast) GetClosingType() ClosingType { + if x != nil { + return x.ClosingType + } + return ClosingType_twoWay +} + +func (x *Forecast) GetClosingReason() ClosingReason { + if x != nil { + return x.ClosingReason + } + return ClosingReason_boatCrossing +} + +func (x *Forecast) GetClosingDuration() *durationpb.Duration { + if x != nil { + return x.ClosingDuration + } + return nil +} + +func (x *Forecast) GetCirculationClosingDate() *timestamppb.Timestamp { + if x != nil { + return x.CirculationClosingDate + } + return nil +} + +func (x *Forecast) GetCirculationReopeningDate() *timestamppb.Timestamp { + if x != nil { + return x.CirculationReopeningDate + } + return nil +} + +func (x *Forecast) GetBoats() []*Boats { + if x != nil { + return x.Boats + } + return nil +} + +type Forecasts struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Forecasts []*Forecast `protobuf:"bytes,1,rep,name=forecasts,proto3" json:"forecasts,omitempty"` +} + +func (x *Forecasts) Reset() { + *x = Forecasts{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_forecast_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Forecasts) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Forecasts) ProtoMessage() {} + +func (x *Forecasts) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_forecast_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Forecasts.ProtoReflect.Descriptor instead. +func (*Forecasts) Descriptor() ([]byte, []int) { + return file_grpc_v1_forecast_proto_rawDescGZIP(), []int{3} +} + +func (x *Forecasts) GetForecasts() []*Forecast { + if x != nil { + return x.Forecasts + } + return nil +} + +var File_grpc_v1_forecast_proto protoreflect.FileDescriptor + +var file_grpc_v1_forecast_proto_rawDesc = []byte{ + 0x0a, 0x16, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x76, 0x31, 0x2f, 0x66, 0x6f, 0x72, 0x65, 0x63, 0x61, + 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, + 0x31, 0x1a, 0x12, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x76, 0x31, 0x2f, 0x62, 0x6f, 0x61, 0x74, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x22, 0x21, 0x0a, 0x0f, 0x46, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x49, + 0x44, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x02, 0x49, 0x44, 0x22, 0xb5, 0x01, 0x0a, 0x0d, 0x46, 0x6f, 0x72, 0x65, 0x63, + 0x61, 0x73, 0x74, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x69, 0x6d, 0x65, + 0x7a, 0x6f, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x74, 0x69, 0x6d, 0x65, + 0x7a, 0x6f, 0x6e, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, + 0x69, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x61, 0x74, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x61, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x61, + 0x6e, 0x65, 0x75, 0x76, 0x65, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6d, 0x61, + 0x6e, 0x65, 0x75, 0x76, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0xa7, + 0x03, 0x0a, 0x08, 0x46, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, + 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x44, 0x12, 0x36, 0x0a, 0x0b, 0x63, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, + 0x32, 0x14, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x69, + 0x6e, 0x67, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0b, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x3c, 0x0a, 0x0d, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x52, 0x65, + 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x16, 0x2e, 0x67, 0x72, 0x70, + 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x61, 0x73, + 0x6f, 0x6e, 0x52, 0x0d, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x61, 0x73, 0x6f, + 0x6e, 0x12, 0x43, 0x0a, 0x0f, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x44, 0x75, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0f, 0x63, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x44, 0x75, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x52, 0x0a, 0x16, 0x63, 0x69, 0x72, 0x63, 0x75, 0x6c, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x52, 0x16, 0x63, 0x69, 0x72, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, + 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x44, 0x61, 0x74, 0x65, 0x12, 0x56, 0x0a, 0x18, 0x63, 0x69, + 0x72, 0x63, 0x75, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x6f, 0x70, 0x65, 0x6e, 0x69, + 0x6e, 0x67, 0x44, 0x61, 0x74, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x18, 0x63, 0x69, 0x72, 0x63, 0x75, 0x6c, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x6f, 0x70, 0x65, 0x6e, 0x69, 0x6e, 0x67, 0x44, 0x61, + 0x74, 0x65, 0x12, 0x24, 0x0a, 0x05, 0x62, 0x6f, 0x61, 0x74, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x0e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x6f, 0x61, 0x74, + 0x73, 0x52, 0x05, 0x62, 0x6f, 0x61, 0x74, 0x73, 0x22, 0x3c, 0x0a, 0x09, 0x46, 0x6f, 0x72, 0x65, + 0x63, 0x61, 0x73, 0x74, 0x73, 0x12, 0x2f, 0x0a, 0x09, 0x66, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, + 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, + 0x76, 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x52, 0x09, 0x66, 0x6f, 0x72, + 0x65, 0x63, 0x61, 0x73, 0x74, 0x73, 0x2a, 0x25, 0x0a, 0x0b, 0x43, 0x6c, 0x6f, 0x73, 0x69, 0x6e, + 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x74, 0x77, 0x6f, 0x57, 0x61, 0x79, 0x10, + 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x6f, 0x6e, 0x65, 0x57, 0x61, 0x79, 0x10, 0x01, 0x2a, 0x32, 0x0a, + 0x0d, 0x43, 0x6c, 0x6f, 0x73, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x10, + 0x0a, 0x0c, 0x62, 0x6f, 0x61, 0x74, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x10, 0x00, + 0x12, 0x0f, 0x0a, 0x0b, 0x6d, 0x61, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x61, 0x6e, 0x63, 0x65, 0x10, + 0x01, 0x32, 0xc5, 0x01, 0x0a, 0x0f, 0x46, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x39, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x46, 0x6f, 0x72, 0x63, + 0x61, 0x73, 0x74, 0x12, 0x18, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x6f, + 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x49, 0x44, 0x51, 0x75, 0x65, 0x72, 0x79, 0x1a, 0x11, 0x2e, + 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, + 0x12, 0x39, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x46, 0x6f, 0x72, 0x63, 0x61, 0x73, 0x74, 0x73, 0x12, + 0x16, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x63, 0x61, + 0x73, 0x74, 0x51, 0x75, 0x65, 0x72, 0x79, 0x1a, 0x12, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, + 0x31, 0x2e, 0x46, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x73, 0x12, 0x3c, 0x0a, 0x0e, 0x47, + 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x46, 0x6f, 0x72, 0x63, 0x61, 0x73, 0x74, 0x73, 0x12, 0x16, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x12, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, + 0x46, 0x6f, 0x72, 0x65, 0x63, 0x61, 0x73, 0x74, 0x73, 0x42, 0x14, 0x5a, 0x12, 0x2f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_grpc_v1_forecast_proto_rawDescOnce sync.Once + file_grpc_v1_forecast_proto_rawDescData = file_grpc_v1_forecast_proto_rawDesc +) + +func file_grpc_v1_forecast_proto_rawDescGZIP() []byte { + file_grpc_v1_forecast_proto_rawDescOnce.Do(func() { + file_grpc_v1_forecast_proto_rawDescData = protoimpl.X.CompressGZIP(file_grpc_v1_forecast_proto_rawDescData) + }) + return file_grpc_v1_forecast_proto_rawDescData +} + +var file_grpc_v1_forecast_proto_enumTypes = make([]protoimpl.EnumInfo, 2) +var file_grpc_v1_forecast_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_grpc_v1_forecast_proto_goTypes = []interface{}{ + (ClosingType)(0), // 0: grpc.v1.ClosingType + (ClosingReason)(0), // 1: grpc.v1.ClosingReason + (*ForecastIDQuery)(nil), // 2: grpc.v1.ForecastIDQuery + (*ForecastQuery)(nil), // 3: grpc.v1.ForecastQuery + (*Forecast)(nil), // 4: grpc.v1.Forecast + (*Forecasts)(nil), // 5: grpc.v1.Forecasts + (*durationpb.Duration)(nil), // 6: google.protobuf.Duration + (*timestamppb.Timestamp)(nil), // 7: google.protobuf.Timestamp + (*Boats)(nil), // 8: grpc.v1.Boats + (*emptypb.Empty)(nil), // 9: google.protobuf.Empty +} +var file_grpc_v1_forecast_proto_depIdxs = []int32{ + 0, // 0: grpc.v1.Forecast.closingType:type_name -> grpc.v1.ClosingType + 1, // 1: grpc.v1.Forecast.closingReason:type_name -> grpc.v1.ClosingReason + 6, // 2: grpc.v1.Forecast.closingDuration:type_name -> google.protobuf.Duration + 7, // 3: grpc.v1.Forecast.circulationClosingDate:type_name -> google.protobuf.Timestamp + 7, // 4: grpc.v1.Forecast.circulationReopeningDate:type_name -> google.protobuf.Timestamp + 8, // 5: grpc.v1.Forecast.boats:type_name -> grpc.v1.Boats + 4, // 6: grpc.v1.Forecasts.forecasts:type_name -> grpc.v1.Forecast + 2, // 7: grpc.v1.ForecastService.GetForcast:input_type -> grpc.v1.ForecastIDQuery + 3, // 8: grpc.v1.ForecastService.GetForcasts:input_type -> grpc.v1.ForecastQuery + 9, // 9: grpc.v1.ForecastService.GetAllForcasts:input_type -> google.protobuf.Empty + 4, // 10: grpc.v1.ForecastService.GetForcast:output_type -> grpc.v1.Forecast + 5, // 11: grpc.v1.ForecastService.GetForcasts:output_type -> grpc.v1.Forecasts + 5, // 12: grpc.v1.ForecastService.GetAllForcasts:output_type -> grpc.v1.Forecasts + 10, // [10:13] is the sub-list for method output_type + 7, // [7:10] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_grpc_v1_forecast_proto_init() } +func file_grpc_v1_forecast_proto_init() { + if File_grpc_v1_forecast_proto != nil { + return + } + file_grpc_v1_boat_proto_init() + if !protoimpl.UnsafeEnabled { + file_grpc_v1_forecast_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ForecastIDQuery); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_v1_forecast_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ForecastQuery); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_v1_forecast_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Forecast); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_v1_forecast_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Forecasts); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_grpc_v1_forecast_proto_rawDesc, + NumEnums: 2, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_grpc_v1_forecast_proto_goTypes, + DependencyIndexes: file_grpc_v1_forecast_proto_depIdxs, + EnumInfos: file_grpc_v1_forecast_proto_enumTypes, + MessageInfos: file_grpc_v1_forecast_proto_msgTypes, + }.Build() + File_grpc_v1_forecast_proto = out.File + file_grpc_v1_forecast_proto_rawDesc = nil + file_grpc_v1_forecast_proto_goTypes = nil + file_grpc_v1_forecast_proto_depIdxs = nil +} diff --git a/internal/generate/forecast_grpc.pb.go b/internal/generate/forecast_grpc.pb.go new file mode 100644 index 0000000..ce814c5 --- /dev/null +++ b/internal/generate/forecast_grpc.pb.go @@ -0,0 +1,184 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.24.3 +// source: grpc/v1/forecast.proto + +package generate + +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.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + ForecastService_GetForcast_FullMethodName = "/grpc.v1.ForecastService/GetForcast" + ForecastService_GetForcasts_FullMethodName = "/grpc.v1.ForecastService/GetForcasts" + ForecastService_GetAllForcasts_FullMethodName = "/grpc.v1.ForecastService/GetAllForcasts" +) + +// ForecastServiceClient is the client API for ForecastService 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 ForecastServiceClient interface { + GetForcast(ctx context.Context, in *ForecastIDQuery, opts ...grpc.CallOption) (*Forecast, error) + GetForcasts(ctx context.Context, in *ForecastQuery, opts ...grpc.CallOption) (*Forecasts, error) + GetAllForcasts(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Forecasts, error) +} + +type forecastServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewForecastServiceClient(cc grpc.ClientConnInterface) ForecastServiceClient { + return &forecastServiceClient{cc} +} + +func (c *forecastServiceClient) GetForcast(ctx context.Context, in *ForecastIDQuery, opts ...grpc.CallOption) (*Forecast, error) { + out := new(Forecast) + err := c.cc.Invoke(ctx, ForecastService_GetForcast_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *forecastServiceClient) GetForcasts(ctx context.Context, in *ForecastQuery, opts ...grpc.CallOption) (*Forecasts, error) { + out := new(Forecasts) + err := c.cc.Invoke(ctx, ForecastService_GetForcasts_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *forecastServiceClient) GetAllForcasts(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Forecasts, error) { + out := new(Forecasts) + err := c.cc.Invoke(ctx, ForecastService_GetAllForcasts_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ForecastServiceServer is the server API for ForecastService service. +// All implementations must embed UnimplementedForecastServiceServer +// for forward compatibility +type ForecastServiceServer interface { + GetForcast(context.Context, *ForecastIDQuery) (*Forecast, error) + GetForcasts(context.Context, *ForecastQuery) (*Forecasts, error) + GetAllForcasts(context.Context, *emptypb.Empty) (*Forecasts, error) + mustEmbedUnimplementedForecastServiceServer() +} + +// UnimplementedForecastServiceServer must be embedded to have forward compatible implementations. +type UnimplementedForecastServiceServer struct { +} + +func (UnimplementedForecastServiceServer) GetForcast(context.Context, *ForecastIDQuery) (*Forecast, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetForcast not implemented") +} +func (UnimplementedForecastServiceServer) GetForcasts(context.Context, *ForecastQuery) (*Forecasts, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetForcasts not implemented") +} +func (UnimplementedForecastServiceServer) GetAllForcasts(context.Context, *emptypb.Empty) (*Forecasts, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetAllForcasts not implemented") +} +func (UnimplementedForecastServiceServer) mustEmbedUnimplementedForecastServiceServer() {} + +// UnsafeForecastServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ForecastServiceServer will +// result in compilation errors. +type UnsafeForecastServiceServer interface { + mustEmbedUnimplementedForecastServiceServer() +} + +func RegisterForecastServiceServer(s grpc.ServiceRegistrar, srv ForecastServiceServer) { + s.RegisterService(&ForecastService_ServiceDesc, srv) +} + +func _ForecastService_GetForcast_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ForecastIDQuery) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForecastServiceServer).GetForcast(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ForecastService_GetForcast_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForecastServiceServer).GetForcast(ctx, req.(*ForecastIDQuery)) + } + return interceptor(ctx, in, info, handler) +} + +func _ForecastService_GetForcasts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ForecastQuery) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ForecastServiceServer).GetForcasts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ForecastService_GetForcasts_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForecastServiceServer).GetForcasts(ctx, req.(*ForecastQuery)) + } + return interceptor(ctx, in, info, handler) +} + +func _ForecastService_GetAllForcasts_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.(ForecastServiceServer).GetAllForcasts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ForecastService_GetAllForcasts_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ForecastServiceServer).GetAllForcasts(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + +// ForecastService_ServiceDesc is the grpc.ServiceDesc for ForecastService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ForecastService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "grpc.v1.ForecastService", + HandlerType: (*ForecastServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetForcast", + Handler: _ForecastService_GetForcast_Handler, + }, + { + MethodName: "GetForcasts", + Handler: _ForecastService_GetForcasts_Handler, + }, + { + MethodName: "GetAllForcasts", + Handler: _ForecastService_GetAllForcasts_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "grpc/v1/forecast.proto", +} diff --git a/internal/generate/healthcheck.pb.go b/internal/generate/healthcheck.pb.go new file mode 100644 index 0000000..22cb466 --- /dev/null +++ b/internal/generate/healthcheck.pb.go @@ -0,0 +1,277 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v4.24.3 +// source: grpc/v1/healthcheck.proto + +package generate + +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 HealthCheckResponse_ServingStatus int32 + +const ( + HealthCheckResponse_UNKNOWN HealthCheckResponse_ServingStatus = 0 + HealthCheckResponse_SERVING HealthCheckResponse_ServingStatus = 1 + HealthCheckResponse_NOT_SERVING HealthCheckResponse_ServingStatus = 2 +) + +// Enum value maps for HealthCheckResponse_ServingStatus. +var ( + HealthCheckResponse_ServingStatus_name = map[int32]string{ + 0: "UNKNOWN", + 1: "SERVING", + 2: "NOT_SERVING", + } + HealthCheckResponse_ServingStatus_value = map[string]int32{ + "UNKNOWN": 0, + "SERVING": 1, + "NOT_SERVING": 2, + } +) + +func (x HealthCheckResponse_ServingStatus) Enum() *HealthCheckResponse_ServingStatus { + p := new(HealthCheckResponse_ServingStatus) + *p = x + return p +} + +func (x HealthCheckResponse_ServingStatus) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (HealthCheckResponse_ServingStatus) Descriptor() protoreflect.EnumDescriptor { + return file_grpc_v1_healthcheck_proto_enumTypes[0].Descriptor() +} + +func (HealthCheckResponse_ServingStatus) Type() protoreflect.EnumType { + return &file_grpc_v1_healthcheck_proto_enumTypes[0] +} + +func (x HealthCheckResponse_ServingStatus) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use HealthCheckResponse_ServingStatus.Descriptor instead. +func (HealthCheckResponse_ServingStatus) EnumDescriptor() ([]byte, []int) { + return file_grpc_v1_healthcheck_proto_rawDescGZIP(), []int{1, 0} +} + +type Empty struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Empty) Reset() { + *x = Empty{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_healthcheck_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_healthcheck_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_grpc_v1_healthcheck_proto_rawDescGZIP(), []int{0} +} + +type HealthCheckResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status HealthCheckResponse_ServingStatus `protobuf:"varint,1,opt,name=status,proto3,enum=grpc.v1.HealthCheckResponse_ServingStatus" json:"status,omitempty"` + Info string `protobuf:"bytes,2,opt,name=info,proto3" json:"info,omitempty"` +} + +func (x *HealthCheckResponse) Reset() { + *x = HealthCheckResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_healthcheck_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HealthCheckResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HealthCheckResponse) ProtoMessage() {} + +func (x *HealthCheckResponse) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_healthcheck_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HealthCheckResponse.ProtoReflect.Descriptor instead. +func (*HealthCheckResponse) Descriptor() ([]byte, []int) { + return file_grpc_v1_healthcheck_proto_rawDescGZIP(), []int{1} +} + +func (x *HealthCheckResponse) GetStatus() HealthCheckResponse_ServingStatus { + if x != nil { + return x.Status + } + return HealthCheckResponse_UNKNOWN +} + +func (x *HealthCheckResponse) GetInfo() string { + if x != nil { + return x.Info + } + return "" +} + +var File_grpc_v1_healthcheck_proto protoreflect.FileDescriptor + +var file_grpc_v1_healthcheck_proto_rawDesc = []byte{ + 0x0a, 0x19, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x63, 0x68, 0x65, 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x67, 0x72, 0x70, + 0x63, 0x2e, 0x76, 0x31, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0xa9, 0x01, + 0x0a, 0x13, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x42, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x2a, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, + 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x69, 0x6e, 0x66, + 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x3a, 0x0a, + 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, + 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x53, + 0x45, 0x52, 0x56, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x4e, 0x4f, 0x54, 0x5f, + 0x53, 0x45, 0x52, 0x56, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x32, 0x90, 0x01, 0x0a, 0x12, 0x48, 0x65, + 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x3b, 0x0a, 0x0b, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x12, + 0x0e, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, + 0x1c, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x43, 0x68, 0x65, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3d, 0x0a, + 0x0b, 0x57, 0x61, 0x74, 0x63, 0x68, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x12, 0x0e, 0x2e, 0x67, + 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1c, 0x2e, 0x67, + 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x43, 0x68, 0x65, + 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x14, 0x5a, 0x12, + 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, + 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_grpc_v1_healthcheck_proto_rawDescOnce sync.Once + file_grpc_v1_healthcheck_proto_rawDescData = file_grpc_v1_healthcheck_proto_rawDesc +) + +func file_grpc_v1_healthcheck_proto_rawDescGZIP() []byte { + file_grpc_v1_healthcheck_proto_rawDescOnce.Do(func() { + file_grpc_v1_healthcheck_proto_rawDescData = protoimpl.X.CompressGZIP(file_grpc_v1_healthcheck_proto_rawDescData) + }) + return file_grpc_v1_healthcheck_proto_rawDescData +} + +var file_grpc_v1_healthcheck_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_grpc_v1_healthcheck_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_grpc_v1_healthcheck_proto_goTypes = []interface{}{ + (HealthCheckResponse_ServingStatus)(0), // 0: grpc.v1.HealthCheckResponse.ServingStatus + (*Empty)(nil), // 1: grpc.v1.Empty + (*HealthCheckResponse)(nil), // 2: grpc.v1.HealthCheckResponse +} +var file_grpc_v1_healthcheck_proto_depIdxs = []int32{ + 0, // 0: grpc.v1.HealthCheckResponse.status:type_name -> grpc.v1.HealthCheckResponse.ServingStatus + 1, // 1: grpc.v1.HealthCheckService.CheckHealth:input_type -> grpc.v1.Empty + 1, // 2: grpc.v1.HealthCheckService.WatchHealth:input_type -> grpc.v1.Empty + 2, // 3: grpc.v1.HealthCheckService.CheckHealth:output_type -> grpc.v1.HealthCheckResponse + 2, // 4: grpc.v1.HealthCheckService.WatchHealth:output_type -> grpc.v1.HealthCheckResponse + 3, // [3:5] is the sub-list for method output_type + 1, // [1:3] 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_grpc_v1_healthcheck_proto_init() } +func file_grpc_v1_healthcheck_proto_init() { + if File_grpc_v1_healthcheck_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_grpc_v1_healthcheck_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Empty); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_v1_healthcheck_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HealthCheckResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_grpc_v1_healthcheck_proto_rawDesc, + NumEnums: 1, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_grpc_v1_healthcheck_proto_goTypes, + DependencyIndexes: file_grpc_v1_healthcheck_proto_depIdxs, + EnumInfos: file_grpc_v1_healthcheck_proto_enumTypes, + MessageInfos: file_grpc_v1_healthcheck_proto_msgTypes, + }.Build() + File_grpc_v1_healthcheck_proto = out.File + file_grpc_v1_healthcheck_proto_rawDesc = nil + file_grpc_v1_healthcheck_proto_goTypes = nil + file_grpc_v1_healthcheck_proto_depIdxs = nil +} diff --git a/internal/generate/healthcheck_grpc.pb.go b/internal/generate/healthcheck_grpc.pb.go new file mode 100644 index 0000000..be10efa --- /dev/null +++ b/internal/generate/healthcheck_grpc.pb.go @@ -0,0 +1,174 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.24.3 +// source: grpc/v1/healthcheck.proto + +package generate + +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.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + HealthCheckService_CheckHealth_FullMethodName = "/grpc.v1.HealthCheckService/CheckHealth" + HealthCheckService_WatchHealth_FullMethodName = "/grpc.v1.HealthCheckService/WatchHealth" +) + +// HealthCheckServiceClient is the client API for HealthCheckService 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 HealthCheckServiceClient interface { + CheckHealth(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*HealthCheckResponse, error) + WatchHealth(ctx context.Context, in *Empty, opts ...grpc.CallOption) (HealthCheckService_WatchHealthClient, error) +} + +type healthCheckServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewHealthCheckServiceClient(cc grpc.ClientConnInterface) HealthCheckServiceClient { + return &healthCheckServiceClient{cc} +} + +func (c *healthCheckServiceClient) CheckHealth(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*HealthCheckResponse, error) { + out := new(HealthCheckResponse) + err := c.cc.Invoke(ctx, HealthCheckService_CheckHealth_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *healthCheckServiceClient) WatchHealth(ctx context.Context, in *Empty, opts ...grpc.CallOption) (HealthCheckService_WatchHealthClient, error) { + stream, err := c.cc.NewStream(ctx, &HealthCheckService_ServiceDesc.Streams[0], HealthCheckService_WatchHealth_FullMethodName, opts...) + if err != nil { + return nil, err + } + x := &healthCheckServiceWatchHealthClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type HealthCheckService_WatchHealthClient interface { + Recv() (*HealthCheckResponse, error) + grpc.ClientStream +} + +type healthCheckServiceWatchHealthClient struct { + grpc.ClientStream +} + +func (x *healthCheckServiceWatchHealthClient) Recv() (*HealthCheckResponse, error) { + m := new(HealthCheckResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// HealthCheckServiceServer is the server API for HealthCheckService service. +// All implementations must embed UnimplementedHealthCheckServiceServer +// for forward compatibility +type HealthCheckServiceServer interface { + CheckHealth(context.Context, *Empty) (*HealthCheckResponse, error) + WatchHealth(*Empty, HealthCheckService_WatchHealthServer) error + mustEmbedUnimplementedHealthCheckServiceServer() +} + +// UnimplementedHealthCheckServiceServer must be embedded to have forward compatible implementations. +type UnimplementedHealthCheckServiceServer struct { +} + +func (UnimplementedHealthCheckServiceServer) CheckHealth(context.Context, *Empty) (*HealthCheckResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CheckHealth not implemented") +} +func (UnimplementedHealthCheckServiceServer) WatchHealth(*Empty, HealthCheckService_WatchHealthServer) error { + return status.Errorf(codes.Unimplemented, "method WatchHealth not implemented") +} +func (UnimplementedHealthCheckServiceServer) mustEmbedUnimplementedHealthCheckServiceServer() {} + +// UnsafeHealthCheckServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to HealthCheckServiceServer will +// result in compilation errors. +type UnsafeHealthCheckServiceServer interface { + mustEmbedUnimplementedHealthCheckServiceServer() +} + +func RegisterHealthCheckServiceServer(s grpc.ServiceRegistrar, srv HealthCheckServiceServer) { + s.RegisterService(&HealthCheckService_ServiceDesc, srv) +} + +func _HealthCheckService_CheckHealth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HealthCheckServiceServer).CheckHealth(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: HealthCheckService_CheckHealth_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HealthCheckServiceServer).CheckHealth(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _HealthCheckService_WatchHealth_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(Empty) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(HealthCheckServiceServer).WatchHealth(m, &healthCheckServiceWatchHealthServer{stream}) +} + +type HealthCheckService_WatchHealthServer interface { + Send(*HealthCheckResponse) error + grpc.ServerStream +} + +type healthCheckServiceWatchHealthServer struct { + grpc.ServerStream +} + +func (x *healthCheckServiceWatchHealthServer) Send(m *HealthCheckResponse) error { + return x.ServerStream.SendMsg(m) +} + +// HealthCheckService_ServiceDesc is the grpc.ServiceDesc for HealthCheckService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var HealthCheckService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "grpc.v1.HealthCheckService", + HandlerType: (*HealthCheckServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CheckHealth", + Handler: _HealthCheckService_CheckHealth_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "WatchHealth", + Handler: _HealthCheckService_WatchHealth_Handler, + ServerStreams: true, + }, + }, + Metadata: "grpc/v1/healthcheck.proto", +} diff --git a/internal/generate/refresh_event.pb.go b/internal/generate/refresh_event.pb.go new file mode 100644 index 0000000..4c3670e --- /dev/null +++ b/internal/generate/refresh_event.pb.go @@ -0,0 +1,198 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v4.24.3 +// source: grpc/v1/refresh_event.proto + +package generate + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + durationpb "google.golang.org/protobuf/types/known/durationpb" + emptypb "google.golang.org/protobuf/types/known/emptypb" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + 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 RefreshResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"` + ItemCount int32 `protobuf:"varint,2,opt,name=itemCount,proto3" json:"itemCount,omitempty"` + Duration *durationpb.Duration `protobuf:"bytes,3,opt,name=duration,proto3" json:"duration,omitempty"` + Timestamp *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"` +} + +func (x *RefreshResponse) Reset() { + *x = RefreshResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_v1_refresh_event_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RefreshResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RefreshResponse) ProtoMessage() {} + +func (x *RefreshResponse) ProtoReflect() protoreflect.Message { + mi := &file_grpc_v1_refresh_event_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RefreshResponse.ProtoReflect.Descriptor instead. +func (*RefreshResponse) Descriptor() ([]byte, []int) { + return file_grpc_v1_refresh_event_proto_rawDescGZIP(), []int{0} +} + +func (x *RefreshResponse) GetID() string { + if x != nil { + return x.ID + } + return "" +} + +func (x *RefreshResponse) GetItemCount() int32 { + if x != nil { + return x.ItemCount + } + return 0 +} + +func (x *RefreshResponse) GetDuration() *durationpb.Duration { + if x != nil { + return x.Duration + } + return nil +} + +func (x *RefreshResponse) GetTimestamp() *timestamppb.Timestamp { + if x != nil { + return x.Timestamp + } + return nil +} + +var File_grpc_v1_refresh_event_proto protoreflect.FileDescriptor + +var file_grpc_v1_refresh_event_proto_rawDesc = []byte{ + 0x0a, 0x1b, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, + 0x68, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x67, + 0x72, 0x70, 0x63, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb0, 0x01, 0x0a, 0x0f, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x49, 0x44, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x74, 0x65, 0x6d, + 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x69, 0x74, 0x65, + 0x6d, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x38, 0x0a, + 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x32, 0x5c, 0x0a, 0x16, 0x52, 0x65, 0x66, 0x72, 0x65, + 0x73, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x42, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x4c, 0x61, 0x73, 0x74, 0x52, 0x65, 0x66, 0x72, + 0x65, 0x73, 0x68, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x18, 0x2e, 0x67, 0x72, + 0x70, 0x63, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x14, 0x5a, 0x12, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_grpc_v1_refresh_event_proto_rawDescOnce sync.Once + file_grpc_v1_refresh_event_proto_rawDescData = file_grpc_v1_refresh_event_proto_rawDesc +) + +func file_grpc_v1_refresh_event_proto_rawDescGZIP() []byte { + file_grpc_v1_refresh_event_proto_rawDescOnce.Do(func() { + file_grpc_v1_refresh_event_proto_rawDescData = protoimpl.X.CompressGZIP(file_grpc_v1_refresh_event_proto_rawDescData) + }) + return file_grpc_v1_refresh_event_proto_rawDescData +} + +var file_grpc_v1_refresh_event_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_grpc_v1_refresh_event_proto_goTypes = []interface{}{ + (*RefreshResponse)(nil), // 0: grpc.v1.RefreshResponse + (*durationpb.Duration)(nil), // 1: google.protobuf.Duration + (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp + (*emptypb.Empty)(nil), // 3: google.protobuf.Empty +} +var file_grpc_v1_refresh_event_proto_depIdxs = []int32{ + 1, // 0: grpc.v1.RefreshResponse.duration:type_name -> google.protobuf.Duration + 2, // 1: grpc.v1.RefreshResponse.timestamp:type_name -> google.protobuf.Timestamp + 3, // 2: grpc.v1.RefreshResponseService.GetLastRefresh:input_type -> google.protobuf.Empty + 0, // 3: grpc.v1.RefreshResponseService.GetLastRefresh:output_type -> grpc.v1.RefreshResponse + 3, // [3:4] is the sub-list for method output_type + 2, // [2:3] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_grpc_v1_refresh_event_proto_init() } +func file_grpc_v1_refresh_event_proto_init() { + if File_grpc_v1_refresh_event_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_grpc_v1_refresh_event_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*RefreshResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_grpc_v1_refresh_event_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_grpc_v1_refresh_event_proto_goTypes, + DependencyIndexes: file_grpc_v1_refresh_event_proto_depIdxs, + MessageInfos: file_grpc_v1_refresh_event_proto_msgTypes, + }.Build() + File_grpc_v1_refresh_event_proto = out.File + file_grpc_v1_refresh_event_proto_rawDesc = nil + file_grpc_v1_refresh_event_proto_goTypes = nil + file_grpc_v1_refresh_event_proto_depIdxs = nil +} diff --git a/internal/generate/refresh_event_grpc.pb.go b/internal/generate/refresh_event_grpc.pb.go new file mode 100644 index 0000000..eb74675 --- /dev/null +++ b/internal/generate/refresh_event_grpc.pb.go @@ -0,0 +1,111 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v4.24.3 +// source: grpc/v1/refresh_event.proto + +package generate + +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.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + RefreshResponseService_GetLastRefresh_FullMethodName = "/grpc.v1.RefreshResponseService/GetLastRefresh" +) + +// RefreshResponseServiceClient is the client API for RefreshResponseService 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 RefreshResponseServiceClient interface { + GetLastRefresh(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*RefreshResponse, error) +} + +type refreshResponseServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewRefreshResponseServiceClient(cc grpc.ClientConnInterface) RefreshResponseServiceClient { + return &refreshResponseServiceClient{cc} +} + +func (c *refreshResponseServiceClient) GetLastRefresh(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*RefreshResponse, error) { + out := new(RefreshResponse) + err := c.cc.Invoke(ctx, RefreshResponseService_GetLastRefresh_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// RefreshResponseServiceServer is the server API for RefreshResponseService service. +// All implementations must embed UnimplementedRefreshResponseServiceServer +// for forward compatibility +type RefreshResponseServiceServer interface { + GetLastRefresh(context.Context, *emptypb.Empty) (*RefreshResponse, error) + mustEmbedUnimplementedRefreshResponseServiceServer() +} + +// UnimplementedRefreshResponseServiceServer must be embedded to have forward compatible implementations. +type UnimplementedRefreshResponseServiceServer struct { +} + +func (UnimplementedRefreshResponseServiceServer) GetLastRefresh(context.Context, *emptypb.Empty) (*RefreshResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetLastRefresh not implemented") +} +func (UnimplementedRefreshResponseServiceServer) mustEmbedUnimplementedRefreshResponseServiceServer() { +} + +// UnsafeRefreshResponseServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to RefreshResponseServiceServer will +// result in compilation errors. +type UnsafeRefreshResponseServiceServer interface { + mustEmbedUnimplementedRefreshResponseServiceServer() +} + +func RegisterRefreshResponseServiceServer(s grpc.ServiceRegistrar, srv RefreshResponseServiceServer) { + s.RegisterService(&RefreshResponseService_ServiceDesc, srv) +} + +func _RefreshResponseService_GetLastRefresh_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.(RefreshResponseServiceServer).GetLastRefresh(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: RefreshResponseService_GetLastRefresh_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(RefreshResponseServiceServer).GetLastRefresh(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + +// RefreshResponseService_ServiceDesc is the grpc.ServiceDesc for RefreshResponseService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var RefreshResponseService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "grpc.v1.RefreshResponseService", + HandlerType: (*RefreshResponseServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetLastRefresh", + Handler: _RefreshResponseService_GetLastRefresh_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "grpc/v1/refresh_event.proto", +} diff --git a/internal/grpc_services/forecast_service.go b/internal/grpc_services/forecast_service.go new file mode 100644 index 0000000..bb897b4 --- /dev/null +++ b/internal/grpc_services/forecast_service.go @@ -0,0 +1,156 @@ +package grpc_services + +import ( + "context" + "fmt" + "log" + "os" + + "github.com/vareversat/chabo-api/internal/models" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" +) + +var ( + WarningLogger = log.New(os.Stdout, "WARNING: ", log.LUTC|log.Ltime|log.Lshortfile) + InfoLogger = log.New(os.Stdout, "INFO: ", log.LUTC|log.Ltime|log.Lshortfile) + ErrorLogger = log.New(os.Stdout, "ERROR: ", log.LUTC|log.Ltime|log.Lshortfile) +) + +type ForecastService struct { + collection *mongo.Collection + ctx context.Context +} + +func NewForecastService(collection *mongo.Collection, ctx context.Context) *ForecastService { + return &ForecastService{collection, ctx} +} + +// Get all forecasts matching the filters +func (fs *ForecastService) GetAllForecasts( + mongoResponse *models.MongoResponse, + limit int, + offset int, + filter bson.D, +) (int, error) { + + cursor, err := getCursor(filter, limit, offset, fs.collection) + + for cursor.Next(context.TODO()) { + if err := cursor.Decode(&mongoResponse); err != nil { + ErrorLogger.Printf(err.Error()) + + return 0, err + } + } + + if err != nil { + ErrorLogger.Printf(err.Error()) + + return 0, err + } + + InfoLogger.Printf("(GetAllForecasts) %d records retrieved !\n", len(mongoResponse.Results)) + + return mongoResponse.Count[0].ItemCount, nil + +} + +// Get a forcast by its unique ID +func (fs *ForecastService) GetForecastbyID(forecast *models.Forecast, ID string) error { + + opts := options.FindOne() + filter := bson.D{{Key: "_id", Value: ID}} + + cursor := fs.collection.FindOne(context.TODO(), filter, opts) + + err := cursor.Decode(&forecast) + + if err != nil { + return fmt.Errorf("not found") + } + + return nil +} + +// Insert all forecast to refresh the data +// Return an error and wither or not it failed under cooldown (too many request) +func (fs *ForecastService) InsertAllForecasts(forecasts []models.Forecast) (error, bool) { + interfaceRecords := make([]interface{}, len(forecasts)) + + if true { + InfoLogger.Printf("Refresh is needed !") + // Transform to generic interface to be usable by ´coll.InsertMany´ + for i := range forecasts { + interfaceRecords[i] = forecasts[i] + } + + filter := bson.D{} + + deleteResult, err := fs.collection.DeleteMany(context.TODO(), filter) + if err != nil { + ErrorLogger.Printf(err.Error()) + + return err, false + } + WarningLogger.Printf( + "(Delete) %d records deleted in %s !\n", + deleteResult.DeletedCount, + "ForecastsCollectionName", + ) + + insertResult, err := fs.collection.InsertMany(context.TODO(), interfaceRecords) + if err != nil { + ErrorLogger.Printf(err.Error()) + + return err, false + } + WarningLogger.Printf( + "(Insert) %d records inserted in %s !\n", + len(insertResult.InsertedIDs), + "ForecastsCollectionName", + ) + + return nil, false + } else { + WarningLogger.Printf("Refresh is NOT needed !") + return fmt.Errorf("you cannot refresh too many time"), true + } + +} + +func getCursor(filters bson.D, limit int, offset int, coll *mongo.Collection) (*mongo.Cursor, error) { + var cursor *mongo.Cursor + var err error + + // Sort results by circulation_closing_date + sortPipeline := bson.D{ + {Key: "$sort", Value: bson.D{{Key: "circulation_closing_date", Value: 1}}}, + } + // Apply all computed filters with a $match + filtersPipeline := bson.D{{Key: "$match", Value: filters}} + // Format the result to get the total match of the filters even if limit and/or offset change + constraintsPipeline := bson.D{ + { + Key: "$facet", + Value: bson.D{ + { + Key: "results", + Value: bson.A{ + bson.D{{Key: "$skip", Value: offset}}, + bson.D{{Key: "$limit", Value: limit}}, + }, + }, + {Key: "count", Value: bson.A{bson.D{{Key: "$count", Value: "itemCount"}}}}, + }, + }, + } + + cursor, err = coll.Aggregate( + context.TODO(), + mongo.Pipeline{sortPipeline, filtersPipeline, constraintsPipeline}, + ) + + return cursor, err +} diff --git a/internal/grpc_services/healthcheck_server.go b/internal/grpc_services/healthcheck_server.go new file mode 100644 index 0000000..565edbd --- /dev/null +++ b/internal/grpc_services/healthcheck_server.go @@ -0,0 +1,17 @@ +package grpc_services + +import ( + ge "github.com/vareversat/chabo-api/internal/generate" + "go.mongodb.org/mongo-driver/mongo" +) + +type HealthcheckServer struct { + ge.UnimplementedHealthCheckServiceServer + + client *mongo.Client +} + +func NewHealthcheckServer(client *mongo.Client) *HealthcheckServer { + + return &HealthcheckServer{client: client} +} diff --git a/internal/grpc_services/healthcheck_service.go b/internal/grpc_services/healthcheck_service.go new file mode 100644 index 0000000..17f5328 --- /dev/null +++ b/internal/grpc_services/healthcheck_service.go @@ -0,0 +1,69 @@ +package grpc_services + +import ( + "context" + "log" + + ge "github.com/vareversat/chabo-api/internal/generate" + "go.mongodb.org/mongo-driver/mongo" +) + +// Check the MongoDB connection +func ping(client *mongo.Client) error { + + err := client.Ping(context.TODO(), nil) + + if err != nil { + ErrorLogger.Printf(err.Error()) + + return err + } + + return nil + +} + +func (s *HealthcheckServer) CheckHealth(ctx context.Context, req *ge.Empty) (*ge.HealthCheckResponse, error) { + + err := ping(s.client) + + if err == nil { + return &ge.HealthCheckResponse{ + Status: ge.HealthCheckResponse_SERVING, + Info: "the GRPC backend is running properly. Mongo server is reachable", + }, nil + } + + return &ge.HealthCheckResponse{ + Status: ge.HealthCheckResponse_NOT_SERVING, + Info: err.Error(), + }, nil +} + +func (s *HealthcheckServer) WatchHealth(req *ge.Empty, srv ge.HealthCheckService_WatchHealthServer) error { + + err := ping(s.client) + + if err == nil { + resp := ge.HealthCheckResponse{ + Status: ge.HealthCheckResponse_SERVING, + Info: "the GRPC backend is running properly. Mongo server is reachable", + } + if err := srv.Send(&resp); err != nil { + log.Println("error generating response") + return nil + } + } + + resp := ge.HealthCheckResponse{ + Status: ge.HealthCheckResponse_NOT_SERVING, + Info: err.Error(), + } + + if err := srv.Send(&resp); err != nil { + log.Println("error generating response") + return nil + } + + return nil +} diff --git a/internal/grpc_services/refresh_service.go b/internal/grpc_services/refresh_service.go new file mode 100644 index 0000000..80a4035 --- /dev/null +++ b/internal/grpc_services/refresh_service.go @@ -0,0 +1,35 @@ +package grpc_services + +import ( + "context" + "fmt" + + "github.com/vareversat/chabo-api/internal/models" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" +) + +type RefreshService struct { + collection *mongo.Collection + ctx context.Context +} + +func NewRefreshService(collection *mongo.Collection, ctx context.Context) *RefreshService { + return &RefreshService{collection, ctx} +} + +func (rs *RefreshService) GetLastRefresh(refresh *models.Refresh) error { + + opts := options.FindOne().SetSort(bson.D{{Key: "timestamp", Value: -1}}) + cursor := rs.collection.FindOne(context.TODO(), bson.D{}, opts) + + err := cursor.Decode(&refresh) + + if err != nil { + return fmt.Errorf("not found") + } + + return nil + +} diff --git a/main.go b/main.go index f9d8457..bae279d 100644 --- a/main.go +++ b/main.go @@ -1,15 +1,22 @@ package main import ( + "context" + "fmt" "log" + "net" "os" + "time" "github.com/getsentry/sentry-go" - "github.com/vareversat/chabo-api/internal/api" - "github.com/vareversat/chabo-api/internal/db" + ge "github.com/vareversat/chabo-api/internal/generate" + "github.com/vareversat/chabo-api/internal/grpc_services" "github.com/vareversat/chabo-api/internal/models" - "github.com/vareversat/chabo-api/internal/utils" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" ) var ( @@ -19,10 +26,14 @@ var ( SentryDSN = os.Getenv("SENTRY_DSN") Env = os.Getenv("ENV") GinMode = os.Getenv("GIN_MODE") -) -func main() { + forecastCollection *mongo.Collection + forecastService grpc_services.ForecastService + redreshCollection *mongo.Collection + refreshService grpc_services.RefreshService +) +func init() { err := sentry.Init(sentry.ClientOptions{ Dsn: SentryDSN, TracesSampleRate: 1.0, @@ -34,16 +45,44 @@ func main() { } log.Default(). - Println("[CHABO-API] Welcome to Chabo API ! Starting the project in " + Env + " mode (Gin " + GinMode + ")") + Println("[CHABO-API] Welcome to Chabo API ! Starting the project in " + Env + " mode") - mongoClient = db.ConnectToMongoInstace() - if err := utils.GetOpenAPIData(&openDataForecasts); err != nil { + ctx := context.TODO() + + serverAPI := options.ServerAPI(options.ServerAPIVersion1) + + opts := options.Client(). + ApplyURI(os.Getenv("MONGO_DSN")). + SetServerAPIOptions(serverAPI).SetTimeout(5 * time.Second) + mongoClient, err = mongo.Connect(ctx, opts) + if err != nil { panic(err) + } else { + // Send a ping command to test the connection + if err := mongoClient.Ping(ctx, nil); err != nil { + panic(err) + } } - utils.ComputeForecasts(&forecasts, openDataForecasts) - if err, _ := db.InsertAllForecasts(mongoClient, forecasts); err != nil { - panic(err) + fmt.Println("MongoDB successfully connected...") + + // Collections + forecastCollection = mongoClient.Database(os.Getenv("MONGO_DATABASE_NAME")).Collection(os.Getenv("MONGO_FORECASTS_COLLECTION_NAME")) + redreshCollection = mongoClient.Database(os.Getenv("MONGO_DATABASE_NAME")).Collection(os.Getenv("MONGO_REFRESHES_COLLECTION_NAME")) + + // Services + forecastService = *grpc_services.NewForecastService(forecastCollection, ctx) + refreshService = *grpc_services.NewRefreshService(redreshCollection, ctx) +} + +func main() { + healtcheckServer := grpc_services.NewHealthcheckServer(mongoClient) + + grpcServer := grpc.NewServer() + listener, _ := net.Listen("tcp", ":8080") + ge.RegisterHealthCheckServiceServer(grpcServer, healtcheckServer) + reflection.Register(grpcServer) + if err := grpcServer.Serve(listener); err != nil { + log.Fatalf("failed to serve: %v", err) } - api.GinRouter(mongoClient) }