Skip to content

Commit

Permalink
Replaced gRPC dependency with ConnectRpc (#1167)
Browse files Browse the repository at this point in the history
Replaces application code that depended on gRPC with ConnectRPC to align with our current RPC framework, ConnectRPC.

However, the gRPC module is still used in our gRPC health check test code and will be removed once we refactor our health checking codes.
  • Loading branch information
hugehoo authored Feb 25, 2025
1 parent 2fd75be commit 23ed89a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ linters-settings:
wrapcheck:
ignoreSigRegexps:
- github.com/yorkie-team/yorkie # Ignore all methods in internal package
- google.golang.org/grpc/status # Ignore all methods in grpc/status package
- google.golang.org/grpc/internal/status # Ignore all methods in grpc/internal/status package
- context.Context # Ignore all methods in context package

issues:
Expand Down
24 changes: 16 additions & 8 deletions cmd/yorkie/project/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"errors"
"fmt"

"connectrpc.com/connect"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v3"

"github.com/yorkie-team/yorkie/admin"
Expand Down Expand Up @@ -61,13 +61,21 @@ func newCreateCommand() *cobra.Command {
ctx := context.Background()
project, err := cli.CreateProject(ctx, name)
if err != nil {
// TODO(chacha912): consider creating the error details type to remove the dependency on gRPC.
st := status.Convert(err)
for _, detail := range st.Details() {
switch t := detail.(type) {
case *errdetails.BadRequest:
for _, violation := range t.GetFieldViolations() {
cmd.Printf("Invalid Fields: The %q field was wrong: %s\n", violation.GetField(), violation.GetDescription())
var connErr *connect.Error
if errors.As(err, &connErr) {
for _, detail := range connErr.Details() {
value, err := detail.Value()
if err != nil {
continue
}

badReq, ok := value.(*errdetails.BadRequest)
if !ok {
continue
}

for _, violation := range badReq.GetFieldViolations() {
cmd.Printf("Invalid Field: %q - %s\n", violation.GetField(), violation.GetDescription())
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions cmd/yorkie/project/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"errors"
"fmt"

"connectrpc.com/connect"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v3"

"github.com/yorkie-team/yorkie/admin"
Expand Down Expand Up @@ -137,13 +137,21 @@ func newUpdateCommand() *cobra.Command {

updated, err := cli.UpdateProject(ctx, id, updatableProjectFields)
if err != nil {
// TODO(chacha912): consider creating the error details type to remove the dependency on gRPC.
st := status.Convert(err)
for _, detail := range st.Details() {
switch t := detail.(type) {
case *errdetails.BadRequest:
for _, violation := range t.GetFieldViolations() {
cmd.Printf("Invalid Fields: The %q field was wrong: %s\n", violation.GetField(), violation.GetDescription())
var connErr *connect.Error
if errors.As(err, &connErr) {
for _, detail := range connErr.Details() {
value, err := detail.Value()
if err != nil {
continue
}

badReq, ok := value.(*errdetails.BadRequest)
if !ok {
continue
}

for _, violation := range badReq.GetFieldViolations() {
cmd.Printf("Invalid Field: %q - %s\n", violation.GetField(), violation.GetDescription())
}
}
}
Expand Down

0 comments on commit 23ed89a

Please sign in to comment.