first try

This commit is contained in:
2024-11-20 14:31:46 +01:00
parent c74114fe66
commit 2936cca8ca
17 changed files with 1887 additions and 3 deletions

7
grpcapi/README.md Normal file
View File

@@ -0,0 +1,7 @@
# COOPGO Diags gRPC API
Generate Go code from proto files :
```
protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. ./*.proto
```

73
grpcapi/diag.go Normal file
View File

@@ -0,0 +1,73 @@
package grpcapi
import (
"encoding/json"
"git.coopgo.io/coopgo-platform/diags/storage"
"github.com/rs/zerolog/log"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/structpb"
)
func (e Diag) ToStorageType() storage.Diag {
diag := storage.Diag{
ID: e.Id,
Name: e.Name,
Namespace: e.Namespace,
Json_schema: e.JsonSchema,
Ui_schema: e.UiSchema,
Data: map[string]any{},
Deleted: e.Deleted,
}
for k, d := range e.Data.GetFields() {
jsondata, err := protojson.Marshal(d)
if err != nil {
log.Error().Err(err).Msg("")
break
}
var data any
json.Unmarshal(jsondata, &data)
diag.Data[k] = data
}
return diag
}
func DiagFromStorageType(diag *storage.Diag) (*Diag, error) {
d, err := sanitizeData(diag.Data)
if err != nil {
return nil, err
}
data, err := structpb.NewStruct(d)
if err != nil {
log.Error().Err(err).Msg("")
return nil, err
}
return &Diag{
Id: diag.ID,
Name: diag.Name,
Namespace: diag.Namespace,
JsonSchema: diag.Json_schema,
UiSchema: diag.Ui_schema,
Data: data,
Deleted: diag.Deleted,
}, nil
}
func sanitizeData(data map[string]any) (d map[string]any, err error) {
j, err := json.Marshal(data)
if err != nil {
return nil, err
}
if err = json.Unmarshal(j, &d); err != nil {
return nil, err
}
return d, nil
}

191
grpcapi/diag.pb.go Normal file
View File

@@ -0,0 +1,191 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.35.2
// protoc v3.21.12
// source: diag.proto
package grpcapi
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
structpb "google.golang.org/protobuf/types/known/structpb"
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 Diag struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Namespace string `protobuf:"bytes,3,opt,name=namespace,proto3" json:"namespace,omitempty"`
JsonSchema string `protobuf:"bytes,4,opt,name=json_schema,json=jsonSchema,proto3" json:"json_schema,omitempty"`
UiSchema string `protobuf:"bytes,5,opt,name=ui_schema,json=uiSchema,proto3" json:"ui_schema,omitempty"`
Data *structpb.Struct `protobuf:"bytes,6,opt,name=data,proto3" json:"data,omitempty"`
Deleted bool `protobuf:"varint,7,opt,name=deleted,proto3" json:"deleted,omitempty"`
}
func (x *Diag) Reset() {
*x = Diag{}
mi := &file_diag_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Diag) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Diag) ProtoMessage() {}
func (x *Diag) ProtoReflect() protoreflect.Message {
mi := &file_diag_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Diag.ProtoReflect.Descriptor instead.
func (*Diag) Descriptor() ([]byte, []int) {
return file_diag_proto_rawDescGZIP(), []int{0}
}
func (x *Diag) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *Diag) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Diag) GetNamespace() string {
if x != nil {
return x.Namespace
}
return ""
}
func (x *Diag) GetJsonSchema() string {
if x != nil {
return x.JsonSchema
}
return ""
}
func (x *Diag) GetUiSchema() string {
if x != nil {
return x.UiSchema
}
return ""
}
func (x *Diag) GetData() *structpb.Struct {
if x != nil {
return x.Data
}
return nil
}
func (x *Diag) GetDeleted() bool {
if x != nil {
return x.Deleted
}
return false
}
var File_diag_proto protoreflect.FileDescriptor
var file_diag_proto_rawDesc = []byte{
0x0a, 0x0a, 0x64, 0x69, 0x61, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f,
0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73, 0x74,
0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xcd, 0x01, 0x0a, 0x04, 0x44,
0x69, 0x61, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73,
0x70, 0x61, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65,
0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x6a, 0x73, 0x6f, 0x6e, 0x5f, 0x73, 0x63,
0x68, 0x65, 0x6d, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6a, 0x73, 0x6f, 0x6e,
0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x69, 0x5f, 0x73, 0x63, 0x68,
0x65, 0x6d, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x69, 0x53, 0x63, 0x68,
0x65, 0x6d, 0x61, 0x12, 0x2b, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x06, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61,
0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28,
0x08, 0x52, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x42, 0x2d, 0x5a, 0x2b, 0x67, 0x69,
0x74, 0x2e, 0x63, 0x6f, 0x6f, 0x70, 0x67, 0x6f, 0x2e, 0x69, 0x6f, 0x2f, 0x63, 0x6f, 0x6f, 0x70,
0x67, 0x6f, 0x2d, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x2f, 0x64, 0x69, 0x61, 0x67,
0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (
file_diag_proto_rawDescOnce sync.Once
file_diag_proto_rawDescData = file_diag_proto_rawDesc
)
func file_diag_proto_rawDescGZIP() []byte {
file_diag_proto_rawDescOnce.Do(func() {
file_diag_proto_rawDescData = protoimpl.X.CompressGZIP(file_diag_proto_rawDescData)
})
return file_diag_proto_rawDescData
}
var file_diag_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_diag_proto_goTypes = []any{
(*Diag)(nil), // 0: Diag
(*structpb.Struct)(nil), // 1: google.protobuf.Struct
}
var file_diag_proto_depIdxs = []int32{
1, // 0: Diag.data:type_name -> google.protobuf.Struct
1, // [1:1] is the sub-list for method output_type
1, // [1:1] 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_diag_proto_init() }
func file_diag_proto_init() {
if File_diag_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_diag_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_diag_proto_goTypes,
DependencyIndexes: file_diag_proto_depIdxs,
MessageInfos: file_diag_proto_msgTypes,
}.Build()
File_diag_proto = out.File
file_diag_proto_rawDesc = nil
file_diag_proto_goTypes = nil
file_diag_proto_depIdxs = nil
}

15
grpcapi/diag.proto Normal file
View File

@@ -0,0 +1,15 @@
syntax = "proto3";
option go_package = "git.coopgo.io/coopgo-platform/diags/grpcapi";
import "google/protobuf/struct.proto";
message Diag {
string id = 1;
string name = 2;
string namespace = 3;
string json_schema = 4;
string ui_schema = 5;
google.protobuf.Struct data = 6;
bool deleted = 7;
}

637
grpcapi/diags.pb.go Normal file
View File

@@ -0,0 +1,637 @@
//COOPGO Diags gRPC service definition
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.35.2
// protoc v3.21.12
// source: diags.proto
package grpcapi
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
_ "google.golang.org/protobuf/types/known/structpb"
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 CreateDiagRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Diag *Diag `protobuf:"bytes,1,opt,name=diag,proto3" json:"diag,omitempty"`
}
func (x *CreateDiagRequest) Reset() {
*x = CreateDiagRequest{}
mi := &file_diags_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *CreateDiagRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CreateDiagRequest) ProtoMessage() {}
func (x *CreateDiagRequest) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CreateDiagRequest.ProtoReflect.Descriptor instead.
func (*CreateDiagRequest) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{0}
}
func (x *CreateDiagRequest) GetDiag() *Diag {
if x != nil {
return x.Diag
}
return nil
}
type CreateDiagResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Diag *Diag `protobuf:"bytes,2,opt,name=diag,proto3" json:"diag,omitempty"`
}
func (x *CreateDiagResponse) Reset() {
*x = CreateDiagResponse{}
mi := &file_diags_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *CreateDiagResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CreateDiagResponse) ProtoMessage() {}
func (x *CreateDiagResponse) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CreateDiagResponse.ProtoReflect.Descriptor instead.
func (*CreateDiagResponse) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{1}
}
func (x *CreateDiagResponse) GetDiag() *Diag {
if x != nil {
return x.Diag
}
return nil
}
type GetDiagRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *GetDiagRequest) Reset() {
*x = GetDiagRequest{}
mi := &file_diags_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetDiagRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetDiagRequest) ProtoMessage() {}
func (x *GetDiagRequest) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetDiagRequest.ProtoReflect.Descriptor instead.
func (*GetDiagRequest) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{2}
}
func (x *GetDiagRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
type GetDiagResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Diag *Diag `protobuf:"bytes,4,opt,name=diag,proto3" json:"diag,omitempty"`
}
func (x *GetDiagResponse) Reset() {
*x = GetDiagResponse{}
mi := &file_diags_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetDiagResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetDiagResponse) ProtoMessage() {}
func (x *GetDiagResponse) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetDiagResponse.ProtoReflect.Descriptor instead.
func (*GetDiagResponse) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{3}
}
func (x *GetDiagResponse) GetDiag() *Diag {
if x != nil {
return x.Diag
}
return nil
}
type DeleteDiagRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,5,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *DeleteDiagRequest) Reset() {
*x = DeleteDiagRequest{}
mi := &file_diags_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *DeleteDiagRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteDiagRequest) ProtoMessage() {}
func (x *DeleteDiagRequest) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeleteDiagRequest.ProtoReflect.Descriptor instead.
func (*DeleteDiagRequest) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{4}
}
func (x *DeleteDiagRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
type DeleteDiagResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Ok bool `protobuf:"varint,6,opt,name=ok,proto3" json:"ok,omitempty"`
}
func (x *DeleteDiagResponse) Reset() {
*x = DeleteDiagResponse{}
mi := &file_diags_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *DeleteDiagResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteDiagResponse) ProtoMessage() {}
func (x *DeleteDiagResponse) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeleteDiagResponse.ProtoReflect.Descriptor instead.
func (*DeleteDiagResponse) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{5}
}
func (x *DeleteDiagResponse) GetOk() bool {
if x != nil {
return x.Ok
}
return false
}
type GetDiagsRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Namespaces []string `protobuf:"bytes,7,rep,name=namespaces,proto3" json:"namespaces,omitempty"`
Mindate *timestamppb.Timestamp `protobuf:"bytes,8,opt,name=mindate,proto3" json:"mindate,omitempty"`
Maxdate *timestamppb.Timestamp `protobuf:"bytes,9,opt,name=maxdate,proto3" json:"maxdate,omitempty"`
}
func (x *GetDiagsRequest) Reset() {
*x = GetDiagsRequest{}
mi := &file_diags_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetDiagsRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetDiagsRequest) ProtoMessage() {}
func (x *GetDiagsRequest) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetDiagsRequest.ProtoReflect.Descriptor instead.
func (*GetDiagsRequest) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{6}
}
func (x *GetDiagsRequest) GetNamespaces() []string {
if x != nil {
return x.Namespaces
}
return nil
}
func (x *GetDiagsRequest) GetMindate() *timestamppb.Timestamp {
if x != nil {
return x.Mindate
}
return nil
}
func (x *GetDiagsRequest) GetMaxdate() *timestamppb.Timestamp {
if x != nil {
return x.Maxdate
}
return nil
}
type GetDiagsResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Diags []*Diag `protobuf:"bytes,10,rep,name=diags,proto3" json:"diags,omitempty"`
}
func (x *GetDiagsResponse) Reset() {
*x = GetDiagsResponse{}
mi := &file_diags_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetDiagsResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetDiagsResponse) ProtoMessage() {}
func (x *GetDiagsResponse) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[7]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetDiagsResponse.ProtoReflect.Descriptor instead.
func (*GetDiagsResponse) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{7}
}
func (x *GetDiagsResponse) GetDiags() []*Diag {
if x != nil {
return x.Diags
}
return nil
}
type UpdateDiagRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Diag *Diag `protobuf:"bytes,11,opt,name=diag,proto3" json:"diag,omitempty"`
}
func (x *UpdateDiagRequest) Reset() {
*x = UpdateDiagRequest{}
mi := &file_diags_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *UpdateDiagRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdateDiagRequest) ProtoMessage() {}
func (x *UpdateDiagRequest) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpdateDiagRequest.ProtoReflect.Descriptor instead.
func (*UpdateDiagRequest) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{8}
}
func (x *UpdateDiagRequest) GetDiag() *Diag {
if x != nil {
return x.Diag
}
return nil
}
type UpdateDiagResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Diag *Diag `protobuf:"bytes,12,opt,name=diag,proto3" json:"diag,omitempty"`
}
func (x *UpdateDiagResponse) Reset() {
*x = UpdateDiagResponse{}
mi := &file_diags_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *UpdateDiagResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdateDiagResponse) ProtoMessage() {}
func (x *UpdateDiagResponse) ProtoReflect() protoreflect.Message {
mi := &file_diags_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpdateDiagResponse.ProtoReflect.Descriptor instead.
func (*UpdateDiagResponse) Descriptor() ([]byte, []int) {
return file_diags_proto_rawDescGZIP(), []int{9}
}
func (x *UpdateDiagResponse) GetDiag() *Diag {
if x != nil {
return x.Diag
}
return nil
}
var File_diags_proto protoreflect.FileDescriptor
var file_diags_proto_rawDesc = []byte{
0x0a, 0x0b, 0x64, 0x69, 0x61, 0x67, 0x73, 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, 0x1c,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f,
0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0a, 0x64, 0x69,
0x61, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2e, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a,
0x04, 0x64, 0x69, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x44, 0x69,
0x61, 0x67, 0x52, 0x04, 0x64, 0x69, 0x61, 0x67, 0x22, 0x2f, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61,
0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19,
0x0a, 0x04, 0x64, 0x69, 0x61, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x44,
0x69, 0x61, 0x67, 0x52, 0x04, 0x64, 0x69, 0x61, 0x67, 0x22, 0x20, 0x0a, 0x0e, 0x47, 0x65, 0x74,
0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69,
0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x0f, 0x47,
0x65, 0x74, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19,
0x0a, 0x04, 0x64, 0x69, 0x61, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x44,
0x69, 0x61, 0x67, 0x52, 0x04, 0x64, 0x69, 0x61, 0x67, 0x22, 0x23, 0x0a, 0x11, 0x44, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e,
0x0a, 0x02, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x24,
0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x6f, 0x6b, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08,
0x52, 0x02, 0x6f, 0x6b, 0x22, 0x9d, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x44, 0x69, 0x61, 0x67,
0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x6e, 0x61, 0x6d, 0x65,
0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x6e, 0x61,
0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x12, 0x34, 0x0a, 0x07, 0x6d, 0x69, 0x6e, 0x64,
0x61, 0x74, 0x65, 0x18, 0x08, 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, 0x07, 0x6d, 0x69, 0x6e, 0x64, 0x61, 0x74, 0x65, 0x12, 0x34,
0x0a, 0x07, 0x6d, 0x61, 0x78, 0x64, 0x61, 0x74, 0x65, 0x18, 0x09, 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, 0x07, 0x6d, 0x61, 0x78,
0x64, 0x61, 0x74, 0x65, 0x22, 0x2f, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x44, 0x69, 0x61, 0x67, 0x73,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x05, 0x64, 0x69, 0x61, 0x67,
0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x44, 0x69, 0x61, 0x67, 0x52, 0x05,
0x64, 0x69, 0x61, 0x67, 0x73, 0x22, 0x2e, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44,
0x69, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x04, 0x64, 0x69,
0x61, 0x67, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x44, 0x69, 0x61, 0x67, 0x52,
0x04, 0x64, 0x69, 0x61, 0x67, 0x22, 0x2f, 0x0a, 0x12, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44,
0x69, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x64,
0x69, 0x61, 0x67, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x44, 0x69, 0x61, 0x67,
0x52, 0x04, 0x64, 0x69, 0x61, 0x67, 0x32, 0x95, 0x02, 0x0a, 0x05, 0x44, 0x69, 0x61, 0x67, 0x73,
0x12, 0x37, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x12, 0x12,
0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x13, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2e, 0x0a, 0x07, 0x47, 0x65, 0x74,
0x44, 0x69, 0x61, 0x67, 0x12, 0x0f, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x69, 0x61, 0x67, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x31, 0x0a, 0x08, 0x47, 0x65, 0x74,
0x44, 0x69, 0x61, 0x67, 0x73, 0x12, 0x10, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x69, 0x61, 0x67, 0x73,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x69, 0x61,
0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x0a,
0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x12, 0x12, 0x2e, 0x44, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13,
0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x0a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44,
0x69, 0x61, 0x67, 0x12, 0x12, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x44, 0x69, 0x61, 0x67,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
0x44, 0x69, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2d,
0x5a, 0x2b, 0x67, 0x69, 0x74, 0x2e, 0x63, 0x6f, 0x6f, 0x70, 0x67, 0x6f, 0x2e, 0x69, 0x6f, 0x2f,
0x63, 0x6f, 0x6f, 0x70, 0x67, 0x6f, 0x2d, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x2f,
0x64, 0x69, 0x61, 0x67, 0x73, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_diags_proto_rawDescOnce sync.Once
file_diags_proto_rawDescData = file_diags_proto_rawDesc
)
func file_diags_proto_rawDescGZIP() []byte {
file_diags_proto_rawDescOnce.Do(func() {
file_diags_proto_rawDescData = protoimpl.X.CompressGZIP(file_diags_proto_rawDescData)
})
return file_diags_proto_rawDescData
}
var file_diags_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_diags_proto_goTypes = []any{
(*CreateDiagRequest)(nil), // 0: CreateDiagRequest
(*CreateDiagResponse)(nil), // 1: CreateDiagResponse
(*GetDiagRequest)(nil), // 2: GetDiagRequest
(*GetDiagResponse)(nil), // 3: GetDiagResponse
(*DeleteDiagRequest)(nil), // 4: DeleteDiagRequest
(*DeleteDiagResponse)(nil), // 5: DeleteDiagResponse
(*GetDiagsRequest)(nil), // 6: GetDiagsRequest
(*GetDiagsResponse)(nil), // 7: GetDiagsResponse
(*UpdateDiagRequest)(nil), // 8: UpdateDiagRequest
(*UpdateDiagResponse)(nil), // 9: UpdateDiagResponse
(*Diag)(nil), // 10: Diag
(*timestamppb.Timestamp)(nil), // 11: google.protobuf.Timestamp
}
var file_diags_proto_depIdxs = []int32{
10, // 0: CreateDiagRequest.diag:type_name -> Diag
10, // 1: CreateDiagResponse.diag:type_name -> Diag
10, // 2: GetDiagResponse.diag:type_name -> Diag
11, // 3: GetDiagsRequest.mindate:type_name -> google.protobuf.Timestamp
11, // 4: GetDiagsRequest.maxdate:type_name -> google.protobuf.Timestamp
10, // 5: GetDiagsResponse.diags:type_name -> Diag
10, // 6: UpdateDiagRequest.diag:type_name -> Diag
10, // 7: UpdateDiagResponse.diag:type_name -> Diag
0, // 8: Diags.CreateDiag:input_type -> CreateDiagRequest
2, // 9: Diags.GetDiag:input_type -> GetDiagRequest
6, // 10: Diags.GetDiags:input_type -> GetDiagsRequest
4, // 11: Diags.DeleteDiag:input_type -> DeleteDiagRequest
8, // 12: Diags.UpdateDiag:input_type -> UpdateDiagRequest
1, // 13: Diags.CreateDiag:output_type -> CreateDiagResponse
3, // 14: Diags.GetDiag:output_type -> GetDiagResponse
7, // 15: Diags.GetDiags:output_type -> GetDiagsResponse
5, // 16: Diags.DeleteDiag:output_type -> DeleteDiagResponse
9, // 17: Diags.UpdateDiag:output_type -> UpdateDiagResponse
13, // [13:18] is the sub-list for method output_type
8, // [8:13] is the sub-list for method input_type
8, // [8:8] is the sub-list for extension type_name
8, // [8:8] is the sub-list for extension extendee
0, // [0:8] is the sub-list for field type_name
}
func init() { file_diags_proto_init() }
func file_diags_proto_init() {
if File_diags_proto != nil {
return
}
file_diag_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_diags_proto_rawDesc,
NumEnums: 0,
NumMessages: 10,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_diags_proto_goTypes,
DependencyIndexes: file_diags_proto_depIdxs,
MessageInfos: file_diags_proto_msgTypes,
}.Build()
File_diags_proto = out.File
file_diags_proto_rawDesc = nil
file_diags_proto_goTypes = nil
file_diags_proto_depIdxs = nil
}

61
grpcapi/diags.proto Normal file
View File

@@ -0,0 +1,61 @@
//COOPGO Diags gRPC service definition
syntax = "proto3";
option go_package = "git.coopgo.io/coopgo-platform/diags/grpcapi";
import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";
import "diag.proto";
service Diags {
rpc CreateDiag(CreateDiagRequest) returns (CreateDiagResponse) {}
rpc GetDiag(GetDiagRequest) returns (GetDiagResponse) {}
rpc GetDiags(GetDiagsRequest) returns (GetDiagsResponse) {}
rpc DeleteDiag(DeleteDiagRequest) returns (DeleteDiagResponse) {}
rpc UpdateDiag(UpdateDiagRequest) returns (UpdateDiagResponse) {}
}
message CreateDiagRequest {
Diag diag = 1;
}
message CreateDiagResponse {
Diag diag = 2;
}
message GetDiagRequest {
string id = 3;
}
message GetDiagResponse {
Diag diag = 4;
}
message DeleteDiagRequest {
string id = 5;
}
message DeleteDiagResponse {
bool ok = 6;
}
message GetDiagsRequest {
repeated string namespaces = 7;
google.protobuf.Timestamp mindate = 8;
google.protobuf.Timestamp maxdate = 9;
}
message GetDiagsResponse {
repeated Diag diags = 10;
}
message UpdateDiagRequest {
Diag diag = 11;
}
message UpdateDiagResponse {
Diag diag = 12;
}

275
grpcapi/diags_grpc.pb.go Normal file
View File

@@ -0,0 +1,275 @@
//COOPGO Diags gRPC service definition
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.21.12
// source: diags.proto
package grpcapi
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Diags_CreateDiag_FullMethodName = "/Diags/CreateDiag"
Diags_GetDiag_FullMethodName = "/Diags/GetDiag"
Diags_GetDiags_FullMethodName = "/Diags/GetDiags"
Diags_DeleteDiag_FullMethodName = "/Diags/DeleteDiag"
Diags_UpdateDiag_FullMethodName = "/Diags/UpdateDiag"
)
// DiagsClient is the client API for Diags 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 DiagsClient interface {
CreateDiag(ctx context.Context, in *CreateDiagRequest, opts ...grpc.CallOption) (*CreateDiagResponse, error)
GetDiag(ctx context.Context, in *GetDiagRequest, opts ...grpc.CallOption) (*GetDiagResponse, error)
GetDiags(ctx context.Context, in *GetDiagsRequest, opts ...grpc.CallOption) (*GetDiagsResponse, error)
DeleteDiag(ctx context.Context, in *DeleteDiagRequest, opts ...grpc.CallOption) (*DeleteDiagResponse, error)
UpdateDiag(ctx context.Context, in *UpdateDiagRequest, opts ...grpc.CallOption) (*UpdateDiagResponse, error)
}
type diagsClient struct {
cc grpc.ClientConnInterface
}
func NewDiagsClient(cc grpc.ClientConnInterface) DiagsClient {
return &diagsClient{cc}
}
func (c *diagsClient) CreateDiag(ctx context.Context, in *CreateDiagRequest, opts ...grpc.CallOption) (*CreateDiagResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CreateDiagResponse)
err := c.cc.Invoke(ctx, Diags_CreateDiag_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *diagsClient) GetDiag(ctx context.Context, in *GetDiagRequest, opts ...grpc.CallOption) (*GetDiagResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetDiagResponse)
err := c.cc.Invoke(ctx, Diags_GetDiag_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *diagsClient) GetDiags(ctx context.Context, in *GetDiagsRequest, opts ...grpc.CallOption) (*GetDiagsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetDiagsResponse)
err := c.cc.Invoke(ctx, Diags_GetDiags_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *diagsClient) DeleteDiag(ctx context.Context, in *DeleteDiagRequest, opts ...grpc.CallOption) (*DeleteDiagResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(DeleteDiagResponse)
err := c.cc.Invoke(ctx, Diags_DeleteDiag_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *diagsClient) UpdateDiag(ctx context.Context, in *UpdateDiagRequest, opts ...grpc.CallOption) (*UpdateDiagResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdateDiagResponse)
err := c.cc.Invoke(ctx, Diags_UpdateDiag_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// DiagsServer is the server API for Diags service.
// All implementations must embed UnimplementedDiagsServer
// for forward compatibility.
type DiagsServer interface {
CreateDiag(context.Context, *CreateDiagRequest) (*CreateDiagResponse, error)
GetDiag(context.Context, *GetDiagRequest) (*GetDiagResponse, error)
GetDiags(context.Context, *GetDiagsRequest) (*GetDiagsResponse, error)
DeleteDiag(context.Context, *DeleteDiagRequest) (*DeleteDiagResponse, error)
UpdateDiag(context.Context, *UpdateDiagRequest) (*UpdateDiagResponse, error)
mustEmbedUnimplementedDiagsServer()
}
// UnimplementedDiagsServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedDiagsServer struct{}
func (UnimplementedDiagsServer) CreateDiag(context.Context, *CreateDiagRequest) (*CreateDiagResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateDiag not implemented")
}
func (UnimplementedDiagsServer) GetDiag(context.Context, *GetDiagRequest) (*GetDiagResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDiag not implemented")
}
func (UnimplementedDiagsServer) GetDiags(context.Context, *GetDiagsRequest) (*GetDiagsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDiags not implemented")
}
func (UnimplementedDiagsServer) DeleteDiag(context.Context, *DeleteDiagRequest) (*DeleteDiagResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteDiag not implemented")
}
func (UnimplementedDiagsServer) UpdateDiag(context.Context, *UpdateDiagRequest) (*UpdateDiagResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateDiag not implemented")
}
func (UnimplementedDiagsServer) mustEmbedUnimplementedDiagsServer() {}
func (UnimplementedDiagsServer) testEmbeddedByValue() {}
// UnsafeDiagsServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to DiagsServer will
// result in compilation errors.
type UnsafeDiagsServer interface {
mustEmbedUnimplementedDiagsServer()
}
func RegisterDiagsServer(s grpc.ServiceRegistrar, srv DiagsServer) {
// If the following call pancis, it indicates UnimplementedDiagsServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Diags_ServiceDesc, srv)
}
func _Diags_CreateDiag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CreateDiagRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DiagsServer).CreateDiag(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Diags_CreateDiag_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DiagsServer).CreateDiag(ctx, req.(*CreateDiagRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Diags_GetDiag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetDiagRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DiagsServer).GetDiag(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Diags_GetDiag_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DiagsServer).GetDiag(ctx, req.(*GetDiagRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Diags_GetDiags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetDiagsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DiagsServer).GetDiags(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Diags_GetDiags_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DiagsServer).GetDiags(ctx, req.(*GetDiagsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Diags_DeleteDiag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeleteDiagRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DiagsServer).DeleteDiag(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Diags_DeleteDiag_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DiagsServer).DeleteDiag(ctx, req.(*DeleteDiagRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Diags_UpdateDiag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateDiagRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DiagsServer).UpdateDiag(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Diags_UpdateDiag_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DiagsServer).UpdateDiag(ctx, req.(*UpdateDiagRequest))
}
return interceptor(ctx, in, info, handler)
}
// Diags_ServiceDesc is the grpc.ServiceDesc for Diags service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Diags_ServiceDesc = grpc.ServiceDesc{
ServiceName: "Diags",
HandlerType: (*DiagsServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "CreateDiag",
Handler: _Diags_CreateDiag_Handler,
},
{
MethodName: "GetDiag",
Handler: _Diags_GetDiag_Handler,
},
{
MethodName: "GetDiags",
Handler: _Diags_GetDiags_Handler,
},
{
MethodName: "DeleteDiag",
Handler: _Diags_DeleteDiag_Handler,
},
{
MethodName: "UpdateDiag",
Handler: _Diags_UpdateDiag_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "diags.proto",
}

131
grpcapi/grpcapi.go Normal file
View File

@@ -0,0 +1,131 @@
package grpcapi
import (
context "context"
"net"
"time"
"git.coopgo.io/coopgo-platform/diags/handlers"
// "git.coopgo.io/coopgo-platform/diags/storage"
// timestamp "github.com/golang/protobuf/ptypes/timestamp"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
"google.golang.org/grpc/reflection"
status "google.golang.org/grpc/status"
// "google.golang.org/protobuf/types/known/structpb"
)
type DiagsServerImpl struct {
handler handlers.DiagsHandler
}
func NewDiagsServer(h handlers.DiagsHandler) *DiagsServerImpl {
return &DiagsServerImpl{
handler: h,
}
}
func (s DiagsServerImpl) CreateDiag(ctx context.Context, req *CreateDiagRequest) (*CreateDiagResponse, error) {
e := req.Diag.ToStorageType()
diag, err := s.handler.CreateDiag(e)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.AlreadyExists, "diag creation failed : %v", err)
}
response, err := DiagFromStorageType(diag)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "issue while retrieving diag : %v", err)
}
return &CreateDiagResponse{Diag: response}, nil
}
func (s DiagsServerImpl) GetDiag(ctx context.Context, req *GetDiagRequest) (*GetDiagResponse, error) {
diag, err := s.handler.GetDiag(req.Id)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.AlreadyExists, "issue while retrieving diag : %v", err)
}
response, err := DiagFromStorageType(diag)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "issue while retrieving diag : %v", err)
}
return &GetDiagResponse{Diag: response}, nil
}
func (s DiagsServerImpl) GetDiags(ctx context.Context, req *GetDiagsRequest) (*GetDiagsResponse, error) {
var mindate, maxdate *time.Time
if req.Mindate != nil {
m := req.Mindate.AsTime()
mindate = &m
}
if req.Maxdate != nil {
m := req.Maxdate.AsTime()
mindate = &m
}
responses, err := s.handler.GetDiags(req.Namespaces, mindate, maxdate)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.NotFound, "could not get diags : %v", err)
}
var diags []*Diag
for _, e := range responses {
diag, err := DiagFromStorageType(&e)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "could not get diags : %v", err)
}
diags = append(diags, diag)
}
return &GetDiagsResponse{Diags: diags}, nil
}
func (s DiagsServerImpl) DeleteDiag(context.Context, *DeleteDiagRequest) (*DeleteDiagResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteDiag not implemented")
}
func (s DiagsServerImpl) UpdateDiag(ctx context.Context, req *UpdateDiagRequest) (*UpdateDiagResponse, error) {
b := req.Diag.ToStorageType()
diag, err := s.handler.UpdateDiag(b)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.AlreadyExists, "diag update failed : %v", err)
}
response, err := DiagFromStorageType(diag)
if err != nil {
log.Error().Err(err).Msg("")
return nil, status.Errorf(codes.Internal, "issue while retrieving diag : %v", err)
}
return &UpdateDiagResponse{Diag: response}, nil
}
func (s DiagsServerImpl) mustEmbedUnimplementedDiagsServer() {}
func Run(done chan error, cfg *viper.Viper, handler handlers.DiagsHandler) {
var (
dev_env = cfg.GetBool("dev_env")
address = ":" + cfg.GetString("services.grpc.port")
)
log.Info().Str("address", address).Msg("Running gRPC server")
server := grpc.NewServer()
RegisterDiagsServer(server, NewDiagsServer(handler))
l, err := net.Listen("tcp", address)
if err != nil {
log.Fatal().Str("address", address).Err(err).Msg("Cannot listen to address")
}
if dev_env {
reflection.Register(server)
}
if err := server.Serve(l); err != nil {
log.Error().Err(err).Msg("gRPC service ended")
done <- err
}
}