logging + cleanup

This commit is contained in:
rushtehrani
2019-12-06 22:52:32 -08:00
parent 703740279a
commit 111ad1ef29
4 changed files with 93 additions and 14 deletions

View File

@@ -66,6 +66,7 @@ func (m *CreateWorkflowRequest) GetWorkflow() *Workflow {
type Workflow struct {
Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Parameters []*Parameter `protobuf:"bytes,3,rep,name=parameters,proto3" json:"parameters,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@@ -110,25 +111,84 @@ func (m *Workflow) GetName() string {
return ""
}
func (m *Workflow) GetParameters() []*Parameter {
if m != nil {
return m.Parameters
}
return nil
}
type Parameter struct {
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Parameter) Reset() { *m = Parameter{} }
func (m *Parameter) String() string { return proto.CompactTextString(m) }
func (*Parameter) ProtoMessage() {}
func (*Parameter) Descriptor() ([]byte, []int) {
return fileDescriptor_892c7f566756b0be, []int{2}
}
func (m *Parameter) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Parameter.Unmarshal(m, b)
}
func (m *Parameter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Parameter.Marshal(b, m, deterministic)
}
func (m *Parameter) XXX_Merge(src proto.Message) {
xxx_messageInfo_Parameter.Merge(m, src)
}
func (m *Parameter) XXX_Size() int {
return xxx_messageInfo_Parameter.Size(m)
}
func (m *Parameter) XXX_DiscardUnknown() {
xxx_messageInfo_Parameter.DiscardUnknown(m)
}
var xxx_messageInfo_Parameter proto.InternalMessageInfo
func (m *Parameter) GetKey() string {
if m != nil {
return m.Key
}
return ""
}
func (m *Parameter) GetValue() string {
if m != nil {
return m.Value
}
return ""
}
func init() {
proto.RegisterType((*CreateWorkflowRequest)(nil), "api.CreateWorkflowRequest")
proto.RegisterType((*Workflow)(nil), "api.Workflow")
proto.RegisterType((*Parameter)(nil), "api.Parameter")
}
func init() { proto.RegisterFile("workflow.proto", fileDescriptor_892c7f566756b0be) }
var fileDescriptor_892c7f566756b0be = []byte{
// 153 bytes of a gzipped FileDescriptorProto
// 213 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2b, 0xcf, 0x2f, 0xca,
0x4e, 0xcb, 0xc9, 0x2f, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54,
0x72, 0xe2, 0x12, 0x75, 0x2e, 0x4a, 0x4d, 0x2c, 0x49, 0x0d, 0x87, 0x4a, 0x06, 0xa5, 0x16, 0x96,
0xa6, 0x16, 0x97, 0x08, 0x69, 0x72, 0x71, 0xc0, 0x84, 0x24, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d,
0x78, 0xf5, 0x12, 0x0b, 0x32, 0xf5, 0xe0, 0xea, 0xe0, 0xd2, 0x4a, 0x46, 0x08, 0xa5, 0x42, 0x42,
0x78, 0xf5, 0x12, 0x0b, 0x32, 0xf5, 0xe0, 0xea, 0xe0, 0xd2, 0x4a, 0x49, 0x08, 0xa5, 0x42, 0x42,
0x5c, 0x2c, 0xa5, 0xa5, 0x99, 0x29, 0x60, 0x2d, 0x9c, 0x41, 0x60, 0x36, 0x48, 0x2c, 0x2f, 0x31,
0x37, 0x55, 0x82, 0x09, 0x22, 0x06, 0x62, 0x1b, 0x79, 0x70, 0xf1, 0xc3, 0xf4, 0x04, 0xa7, 0x16,
0x95, 0x65, 0x26, 0xa7, 0x0a, 0x99, 0x72, 0xb1, 0x41, 0x9c, 0x22, 0x24, 0x05, 0xb6, 0x09, 0xab,
0xbb, 0xa4, 0x50, 0x5d, 0xa1, 0xc4, 0x90, 0xc4, 0x06, 0xf6, 0x8d, 0x31, 0x20, 0x00, 0x00, 0xff,
0xff, 0xa2, 0xfe, 0xa4, 0xef, 0xdf, 0x00, 0x00, 0x00,
0x37, 0x55, 0x82, 0x09, 0x22, 0x06, 0x62, 0x0b, 0xe9, 0x71, 0x71, 0x15, 0x24, 0x16, 0x25, 0xe6,
0xa6, 0x96, 0xa4, 0x16, 0x15, 0x4b, 0x30, 0x2b, 0x30, 0x6b, 0x70, 0x1b, 0xf1, 0x81, 0x2d, 0x08,
0x80, 0x09, 0x07, 0x21, 0xa9, 0x50, 0x32, 0xe6, 0xe2, 0x84, 0x4b, 0x08, 0x09, 0x70, 0x31, 0x67,
0xa7, 0x56, 0x42, 0xed, 0x00, 0x31, 0x85, 0x44, 0xb8, 0x58, 0xcb, 0x12, 0x73, 0x4a, 0x61, 0x76,
0x40, 0x38, 0x46, 0x1e, 0x5c, 0xfc, 0x30, 0x87, 0x05, 0xa7, 0x16, 0x95, 0x65, 0x26, 0xa7, 0x0a,
0x99, 0x72, 0xb1, 0x41, 0xfc, 0x2b, 0x24, 0x05, 0xb6, 0x0d, 0xab, 0xe7, 0xa5, 0x50, 0xbd, 0xaa,
0xc4, 0x90, 0xc4, 0x06, 0x0e, 0x32, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe3, 0x4a, 0x6c,
0xf8, 0x44, 0x01, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.

View File

@@ -14,4 +14,11 @@ message CreateWorkflowRequest {
message Workflow {
string uuid = 1;
string name = 2;
repeated Parameter parameters = 3;
}
message Parameter {
string key = 1;
string value = 2;
}

14
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
"context"
"flag"
"log"
"net"
@@ -60,7 +61,7 @@ func startRPCServer(db *repository.DB) {
log.Fatalf("Failed to start RPC server: %v", err)
}
s := grpc.NewServer()
s := grpc.NewServer(grpc.UnaryInterceptor(loggingInterceptor))
api.RegisterWorkflowServiceServer(s, server.NewWorkflowServer(workflowRepository))
if err := s.Serve(lis); err != nil {
@@ -68,3 +69,14 @@ func startRPCServer(db *repository.DB) {
}
log.Print("RPC server started")
}
func loggingInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
log.Printf("%v handler started", info.FullMethod)
resp, err = handler(ctx, req)
if err != nil {
log.Printf("%s call failed", info.FullMethod)
return
}
log.Printf("%v handler finished", info.FullMethod)
return
}

View File

@@ -15,6 +15,6 @@ func NewWorkflowServer(workflowRepository *repository.WorkflowRepository) *Workf
return &WorkflowServer{workflowRepository: workflowRepository}
}
func (w *WorkflowServer) Create(c context.Context, request *api.CreateWorkflowRequest) (*api.Workflow, error) {
return &api.Workflow{Uuid: "uuid", Name: "name"}, nil
func (w *WorkflowServer) Create(ctx context.Context, req *api.CreateWorkflowRequest) (*api.Workflow, error) {
return req.Workflow, nil
}