Skip to content

Commit

Permalink
feat(grpc): implement the grpc server
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Dec 11, 2023
1 parent f72d9db commit 62a60b5
Show file tree
Hide file tree
Showing 11 changed files with 1,399 additions and 16 deletions.
6 changes: 5 additions & 1 deletion cmd/likit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/CorrectRoadH/Likit/config"
"github.com/CorrectRoadH/Likit/internal/adapter/in/grpc"
"github.com/CorrectRoadH/Likit/internal/adapter/in/restful"
"github.com/CorrectRoadH/Likit/internal/adapter/in/restful/route"
"github.com/CorrectRoadH/Likit/internal/adapter/out/admin"
Expand All @@ -19,6 +20,9 @@ func Main() {

route.NewAdminApiService,

grpc.NewGrpcServer,
grpc.NewVoteGRPCServer,

server.NewVoteServer,
server.NewAdminServer,
server.NewDatabaseServer,
Expand All @@ -34,7 +38,7 @@ func Main() {
database.NewRedisAdapter,
database.NewPostgresAdapter,
),
fx.Invoke(func(s *restful.RESTfulServer) {
fx.Invoke(func(s *restful.RESTfulServer, g *grpc.GrpcServer) {
s.Start()
}),
).Run()
Expand Down
18 changes: 14 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@ module github.com/CorrectRoadH/Likit
go 1.21.4

require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/grpc v1.58.2
google.golang.org/protobuf v1.31.0

)

require (
connectrpc.com/connect v1.13.0
github.com/deepmap/oapi-codegen v1.16.2
github.com/getkin/kin-openapi v0.122.0
github.com/google/uuid v1.4.0
github.com/jackc/pgx/v4 v4.18.1
github.com/labstack/echo/v4 v4.11.3
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
github.com/redis/go-redis/v9 v9.3.0
github.com/sourcegraph/conc v0.3.0
go.uber.org/fx v1.20.1
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)
Expand All @@ -25,7 +37,6 @@ require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/deepmap/oapi-codegen v1.16.2 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/flosch/pongo2/v4 v4.0.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
Expand All @@ -35,17 +46,16 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gomarkdown/markdown v0.0.0-20230716120725-531d2d74bc12 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/iris-contrib/schema v0.0.6 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx/v4 v4.18.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kataras/blocks v0.0.7 // indirect
github.com/kataras/golog v0.1.9 // indirect
Expand All @@ -71,6 +81,7 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yosssi/ace v0.0.5 // indirect
golang.org/x/arch v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)

Expand Down Expand Up @@ -112,6 +123,5 @@ require (
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
57 changes: 55 additions & 2 deletions go.sum

Large diffs are not rendered by default.

32 changes: 23 additions & 9 deletions grpc/api/v1/vote.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ import "google/api/field_behavior.proto";
import "google/protobuf/timestamp.proto";

service VoteService {
rpc Vote(VoteRequest) returns (VoteResponse) {
option (google.api.http) = { get: "/v1/vote" };
}
rpc UnVote(VoteRequest) returns (VoteResponse) {
option (google.api.http) = { get: "/v1/unvote" };
}
rpc Count(CountRequest) returns (CountResponse) {

}
rpc Vote(VoteRequest) returns (VoteResponse) {}
rpc UnVote(VoteRequest) returns (VoteResponse) {}
rpc Count(CountRequest) returns (CountResponse) {}
rpc IsVoted(IsVotedRequest) returns (IsVotedResponse) {}
rpc VotedUsers(VotedUsersRequest) returns (VotedUsersResponse) {}
}


Expand All @@ -40,3 +36,21 @@ message CountResponse {
int64 count = 1;
}

message IsVotedRequest {
string business_id = 1;
string message_id = 2;
string user_id = 3;
}

message IsVotedResponse {
bool is_voted = 1;
}

message VotedUsersRequest {
string business_id = 1;
string message_id = 2;
}

message VotedUsersResponse {
repeated string user_ids = 1;
}
13 changes: 13 additions & 0 deletions grpc/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: b30c5775bfb3485d9da2e87b26590ac9
digest: shake256:9d0caaf056949a0e1c883b9849d8a2fa66e22f18a2a48f867d1a8c700aa22abee50ad3ef0d8171637457cadc43c584998bdf3adac55da0f9e4614c72686b057d
- remote: buf.build
owner: grpc-ecosystem
repository: grpc-gateway
commit: 3f42134f4c564983838425bc43c7a65f
digest: shake256:3d11d4c0fe5e05fda0131afefbce233940e27f0c31c5d4e385686aea58ccd30f72053f61af432fa83f1fc11cda57f5f18ca3da26a29064f73c5a0d076bba8d92
11 changes: 11 additions & 0 deletions grpc/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: v1
name: buf.build/likit/likit
breaking:
use:
- FILE
lint:
use:
- DEFAULT
deps:
- buf.build/googleapis/googleapis
- buf.build/grpc-ecosystem/grpc-gateway
208 changes: 208 additions & 0 deletions grpc/gen/api/v1/apiv1connect/vote.connect.go

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

Loading

0 comments on commit 62a60b5

Please sign in to comment.