Skip to content

Commit

Permalink
Remove grpc and gin related dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dongxuny committed Dec 9, 2021
1 parent b681b9c commit 8700522
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 407 deletions.
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
.PHONY: all
all: buf test lint doctoc fmt

.PHONY: buf
buf:
@echo "[buf] Running buf..."
@buf generate
@echo "------------------------------------[Done]"
all: test lint doctoc fmt

.PHONY: lint
lint:
Expand Down
6 changes: 0 additions & 6 deletions buf.gen.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions buf.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions common/rk.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ const (
RkReadmeFilePath = ".rk/README.md"
)

// NewRkMeta returns empty rk meta instance
func NewRkMeta() *RkMeta {
return &RkMeta{
Git: &Git{
Commit: &Commit{
Committer: &Committer{},
},
},
}
}

// RkMeta would be extracted by rk cli
type RkMeta struct {
// Name of application
Expand Down
20 changes: 0 additions & 20 deletions error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ package rkerror
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"google.golang.org/grpc/codes"
"net/http"
)

Expand Down Expand Up @@ -61,8 +59,6 @@ func WithDetails(details ...interface{}) Option {
detail := details[i]

switch v := detail.(type) {
case *gin.Error:
resp.Err.Details = append(resp.Err.Details, v.JSON())
case *Error:
resp.Err.Details = append(resp.Err.Details, v.Details...)
case error:
Expand All @@ -82,22 +78,6 @@ func WithHttpCode(code int) Option {
}
}

// WithHttpCode provides grpc response code
func WithGrpcCode(code codes.Code) Option {
return func(resp *ErrorResp) {
resp.Err.Code = int(code)
resp.Err.Status = code.String()
}
}

// WithCodeAndStatus provides http response code and status
func WithCodeAndStatus(code int, status string) Option {
return func(resp *ErrorResp) {
resp.Err.Code = code
resp.Err.Status = status
}
}

// WithMessage provides messages along with response
func WithMessage(message string) Option {
return func(resp *ErrorResp) {
Expand Down
32 changes: 1 addition & 31 deletions error/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ package rkerror

import (
"errors"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"net/http"
"testing"
)
Expand All @@ -24,22 +22,8 @@ func TestNew_WithoutOptions(t *testing.T) {
}

func TestNew_WithDetails(t *testing.T) {
// With gin error
ginErr := &gin.Error{
Type: gin.ErrorTypePublic,
Err: errors.New("gin error"),
Meta: "gin meta",
}

res := New(WithDetails(ginErr))

assert.Equal(t, http.StatusInternalServerError, res.Err.Code)
assert.Equal(t, http.StatusText(http.StatusInternalServerError), res.Err.Status)
assert.Equal(t, "gin meta", res.Err.Details[0].(gin.H)["meta"])
assert.Equal(t, "gin error", res.Err.Details[0].(gin.H)["error"])

// With rk error type
res = New(WithDetails("rk error"))
res := New(WithDetails("rk error"))
assert.Equal(t, http.StatusInternalServerError, res.Err.Code)
assert.Equal(t, http.StatusText(http.StatusInternalServerError), res.Err.Status)
assert.Equal(t, "rk error", res.Err.Details[0])
Expand All @@ -64,20 +48,6 @@ func TestNew_WithHttpCode(t *testing.T) {
assert.Equal(t, http.StatusText(http.StatusAlreadyReported), res.Err.Status)
}

func TestNew_WithGrpcCode(t *testing.T) {
res := New(WithGrpcCode(codes.Aborted))

assert.Equal(t, int(codes.Aborted), res.Err.Code)
assert.Equal(t, codes.Aborted.String(), res.Err.Status)
}

func TestNew_WithCodeAndStatus(t *testing.T) {
res := New(WithCodeAndStatus(-1, "ut-status"))

assert.Equal(t, -1, res.Err.Code)
assert.Equal(t, "ut-status", res.Err.Status)
}

func TestNew_WithMessage(t *testing.T) {
res := New(WithMessage("ut message"))

Expand Down
161 changes: 0 additions & 161 deletions error/gen/error.pb.go

This file was deleted.

61 changes: 0 additions & 61 deletions error/grpc_error_wrap.go

This file was deleted.

19 changes: 0 additions & 19 deletions error/grpc_error_wrap_test.go

This file was deleted.

11 changes: 0 additions & 11 deletions error/proto/error.proto

This file was deleted.

Loading

0 comments on commit 8700522

Please sign in to comment.