-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add grpc * Ignore generated files * Update makefile command * Fix docker * Add rpc server * Fix make test * Fix build * Fix make check * Add SSE streaming * Remove generated swagger docs * Adjust gitignore * Fix makefile
- Loading branch information
Showing
11 changed files
with
162 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ dist.zip | |
frontend/dist/ | ||
|
||
# Ignore generated files | ||
*.pb.go | ||
*.pb.go | ||
**/swaggo-gen/docs.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package impls | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/OJ-lab/oj-lab-services/service/proto" | ||
) | ||
|
||
type GreeterServer struct { | ||
proto.UnimplementedGreeterServer | ||
} | ||
|
||
func (s *GreeterServer) Greeting(ctx context.Context, request *proto.GreetingRequest) (*proto.GreetingResponse, error) { | ||
log.Printf("Received: %v", request.GetName()) | ||
return &proto.GreetingResponse{Message: "Hello " + request.GetName()}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package impls | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/OJ-lab/oj-lab-services/service/proto" | ||
) | ||
|
||
type StreamerServer struct { | ||
proto.UnimplementedStreamerServer | ||
} | ||
|
||
func (s *StreamerServer) StartStream(request *proto.StreamRequest, server proto.Streamer_StartStreamServer) error { | ||
tick := time.NewTicker(1 * time.Second) | ||
for range tick.C { | ||
if server.Context().Err() != nil { | ||
if server.Context().Err().Error() == "context canceled" { | ||
log.Printf("client closed stream") | ||
return nil | ||
} | ||
log.Printf("client closed stream with: %v", server.Context().Err().Error()) | ||
return nil | ||
} | ||
|
||
server.Send(&proto.StreamResponse{Body: &proto.StreamResponse_Health{ | ||
Health: &proto.ServerHealth{}, | ||
}}) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net" | ||
|
||
"github.com/OJ-lab/oj-lab-services/application/rpc_server/impls" | ||
"github.com/OJ-lab/oj-lab-services/core" | ||
"github.com/OJ-lab/oj-lab-services/service/proto" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/reflection" | ||
) | ||
|
||
const ( | ||
portProp = "rpc-server.port" | ||
) | ||
|
||
var ( | ||
port = core.AppConfig.GetInt(portProp) | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) | ||
if err != nil { | ||
log.Fatalf("failed to listen: %v", err) | ||
} | ||
s := grpc.NewServer() | ||
proto.RegisterGreeterServer(s, &impls.GreeterServer{}) | ||
proto.RegisterStreamerServer(s, &impls.StreamerServer{}) | ||
|
||
reflection.Register(s) | ||
log.Printf("server listening at %v", lis.Addr()) | ||
if err := s.Serve(lis); err != nil { | ||
log.Fatalf("failed to serve: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
package oj_lab_greeting.protos; | ||
|
||
option go_package = "github.com/OJ-lab/oj-lab-services/service/proto"; | ||
|
||
service Greeter { | ||
rpc Greeting (GreetingRequest) returns (GreetingResponse) {} | ||
} | ||
|
||
message GreetingRequest { | ||
string name = 1; | ||
} | ||
|
||
message GreetingResponse { | ||
string message = 1; | ||
} |
Oops, something went wrong.