Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
issue #166: remove Error from protobuf structs
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Sep 5, 2018
1 parent 0e5498e commit 3f4efbe
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 302 deletions.
28 changes: 14 additions & 14 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ var runCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
runtime.GOMAXPROCS(int(cnf.Union.ServerConfig.CPUCount))

if err := startGRPCServer(cnf.Union.GRPCConfig); err != nil {
dbLayer := storage.Must(storage.Database(cnf.Union.DBConfig))
handler := chi.NewRouter(
server.New(
cnf.Union.ServerConfig,
service.New(dbLayer, dbLayer),
),
)

if err := startGRPCServer(cnf.Union.GRPCConfig, dbLayer); err != nil {
return err
}
if cnf.Union.MonitoringConfig.Enabled {
Expand All @@ -43,14 +51,6 @@ var runCmd = &cobra.Command{
return err
}
}

dbLayer := storage.Must(storage.Database(cnf.Union.DBConfig))
handler := chi.NewRouter(
server.New(
cnf.Union.ServerConfig,
service.New(dbLayer, dbLayer),
),
)
return startHTTPServer(cnf.Union.ServerConfig, handler)
},
}
Expand Down Expand Up @@ -145,17 +145,17 @@ func startHTTPServer(cnf config.ServerConfig, handler http.Handler) error {
return srv.Serve(listener)
}

func startGRPCServer(cnf config.GRPCConfig) error {
func startGRPCServer(cnf config.GRPCConfig, storage pb.ProtectedStorage) error {
listener, err := net.Listen("tcp", cnf.Interface)
if err != nil {
return err
}
go func() {
srv := grpc.NewServer()
pb.RegisterSchemaServer(srv, pb.NewSchemaServer())
pb.RegisterTemplateServer(srv, pb.NewTemplateServer())
pb.RegisterInputServer(srv, pb.NewInputServer())
pb.RegisterLogServer(srv, pb.NewLogServer())
pb.RegisterSchemaServer(srv, pb.NewSchemaServer(storage))
pb.RegisterTemplateServer(srv, pb.NewTemplateServer(storage))
pb.RegisterInputServer(srv, pb.NewInputServer(storage))
pb.RegisterLogServer(srv, pb.NewLogServer(storage))
log.Println("start gRPC server at", listener.Addr())
_ = srv.Serve(listener) // TODO issue#139
listener.Close()
Expand Down
68 changes: 9 additions & 59 deletions pkg/server/grpc/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions pkg/server/grpc/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ package grpc;

import "google/protobuf/timestamp.proto";

message Error {
uint32 code = 1;
string message = 2;
}

message TimestampRange {
google.protobuf.Timestamp start = 1;
google.protobuf.Timestamp end = 2;
Expand Down
85 changes: 37 additions & 48 deletions pkg/server/grpc/event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pkg/server/grpc/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ message ReadLogsRequest {

message ReadLogsResponse {
repeated LogEntry logs = 1;

Error err = 15;
}

message ListenLogsRequest {
Expand Down
6 changes: 4 additions & 2 deletions pkg/server/grpc/server.input.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
)

// NewInputServer returns new instance of server API for Input service.
func NewInputServer() InputServer {
return &inputServer{}
func NewInputServer(storage ProtectedStorage) InputServer {
return &inputServer{storage: storage}
}

type inputServer struct {
storage ProtectedStorage
}

// Read TODO
func (*inputServer) Read(context.Context, *ReadInputRequest) (*ReadInputResponse, error) {
log.Println("InputServer.Read was called")
return &ReadInputResponse{}, nil
Expand Down
7 changes: 5 additions & 2 deletions pkg/server/grpc/server.log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import (
)

// NewLogServer returns new instance of server API for Log service.
func NewLogServer() LogServer {
return &logServer{}
func NewLogServer(storage ProtectedStorage) LogServer {
return &logServer{storage: storage}
}

type logServer struct {
storage ProtectedStorage
}

// Read TODO
func (*logServer) Read(context.Context, *ReadLogsRequest) (*ReadLogsResponse, error) {
log.Println("LogServer.Read was called")
return &ReadLogsResponse{}, nil
}

// Listen TODO
func (*logServer) Listen(*ListenLogsRequest, Log_ListenServer) error {
log.Println("LogServer.Listen was called")
return nil
Expand Down
Loading

0 comments on commit 3f4efbe

Please sign in to comment.