Skip to content

Commit

Permalink
Merge pull request #32 from gone-io/feature/1.x
Browse files Browse the repository at this point in the history
Feature/1.x
  • Loading branch information
Degfy authored Jul 13, 2024
2 parents 65daa2e + ad75c87 commit 7c0c739
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions goner/gin/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type HandleProxyToGin interface {
type XContext interface {
JSON(code int, obj any)
String(code int, format string, values ...any)
Abort()
}

type WrappedDataFunc func(code int, msg string, data any) any
Expand Down
48 changes: 48 additions & 0 deletions goner/gin/mock_test.go

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

8 changes: 8 additions & 0 deletions goner/gin/responer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ func (r *responser) Failed(ctx XContext, oErr error) {
}

func (r *responser) ProcessResults(context XContext, writer gin.ResponseWriter, last bool, funcName string, results ...any) {
for _, result := range results {
if err, ok := result.(error); ok {
r.Failed(context, err)
context.Abort()
return
}
}

isNotEnd := false
for _, result := range results {
if result == nil {
Expand Down
1 change: 1 addition & 0 deletions goner/gin/responer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func Test_responser_ProcessResults(t *testing.T) {
writer := NewMockResponseWriter(controller)

ctx.EXPECT().JSON(gomock.Any(), gomock.Any()).AnyTimes()
ctx.EXPECT().Abort().AnyTimes()

t.Run("last=false", func(t *testing.T) {
writer.EXPECT().Written().Return(false).AnyTimes()
Expand Down

0 comments on commit 7c0c739

Please sign in to comment.