Skip to content

Commit

Permalink
Revert "feat: [#507] Add Abort method for Response (#776)"
Browse files Browse the repository at this point in the history
This reverts commit be88582.
  • Loading branch information
hwbrzzl authored Dec 23, 2024
1 parent 375c494 commit 57085e2
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 322 deletions.
25 changes: 10 additions & 15 deletions contracts/http/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ type ContextResponse interface {
// Cookie adds a cookie to the response.
Cookie(cookie Cookie) ContextResponse
// Data write the given data to the response.
Data(code int, contentType string, data []byte) ResponseWithAbort
Data(code int, contentType string, data []byte) Response
// Download initiates a file download by specifying the file path and the desired filename
Download(filepath, filename string) Response
// File serves a file located at the specified file path as the response.
File(filepath string) Response
// Header sets an HTTP header field with the given key and value.
Header(key, value string) ContextResponse
// Json sends a JSON response with the specified status code and data object.
Json(code int, obj any) ResponseWithAbort
Json(code int, obj any) Response
// NoContent sends a response with no-body and the specified status code.
NoContent(code ...int) ResponseWithAbort
NoContent(code ...int) Response
// Origin returns the ResponseOrigin
Origin() ResponseOrigin
// Redirect performs an HTTP redirect to the specified location with the given status code.
Redirect(code int, location string) ResponseWithAbort
Redirect(code int, location string) Response
// String writes a string response with the specified status code and format.
// The 'values' parameter can be used to replace placeholders in the format string.
String(code int, format string, values ...any) ResponseWithAbort
String(code int, format string, values ...any) Response
// Success returns ResponseStatus with a 200 status code.
Success() ResponseStatus
// Status sets the HTTP response status code and returns the ResponseStatus.
Expand All @@ -49,11 +49,6 @@ type Response interface {
Render() error
}

type ResponseWithAbort interface {
Response
Abort() error
}

type StreamWriter interface {
// Write writes the specified data to the response.
Write(data []byte) (int, error)
Expand All @@ -67,11 +62,11 @@ type StreamWriter interface {

type ResponseStatus interface {
// Data write the given data to the Response.
Data(contentType string, data []byte) ResponseWithAbort
// Json sends a JSON AbortResponse with the specified data object.
Json(obj any) ResponseWithAbort
// String writes a string AbortResponse with the specified format and values.
String(format string, values ...any) ResponseWithAbort
Data(contentType string, data []byte) Response
// Json sends a JSON Response with the specified data object.
Json(obj any) Response
// String writes a string Response with the specified format and values.
String(format string, values ...any) Response
// Stream sends a streaming response with the specified status code and the given reader.
Stream(step func(w StreamWriter) error) Response
}
Expand Down
10 changes: 5 additions & 5 deletions http/middleware/throttle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ func (r *TestResponse) Cookie(cookie contractshttp.Cookie) contractshttp.Context
panic("do not need to implement it")
}

func (r *TestResponse) Data(code int, contentType string, data []byte) contractshttp.ResponseWithAbort {
func (r *TestResponse) Data(code int, contentType string, data []byte) contractshttp.Response {
panic("do not need to implement it")
}

Expand All @@ -612,23 +612,23 @@ func (r *TestResponse) Header(key, value string) contractshttp.ContextResponse {
return r
}

func (r *TestResponse) Json(code int, obj any) contractshttp.ResponseWithAbort {
func (r *TestResponse) Json(code int, obj any) contractshttp.Response {
panic("do not need to implement it")
}

func (r *TestResponse) NoContent(...int) contractshttp.ResponseWithAbort {
func (r *TestResponse) NoContent(...int) contractshttp.Response {
panic("do not need to implement it")
}

func (r *TestResponse) Origin() contractshttp.ResponseOrigin {
panic("do not need to implement it")
}

func (r *TestResponse) Redirect(code int, location string) contractshttp.ResponseWithAbort {
func (r *TestResponse) Redirect(code int, location string) contractshttp.Response {
panic("do not need to implement it")
}

func (r *TestResponse) String(code int, format string, values ...any) contractshttp.ResponseWithAbort {
func (r *TestResponse) String(code int, format string, values ...any) contractshttp.Response {
panic("do not need to implement it")
}

Expand Down
10 changes: 5 additions & 5 deletions log/logrus_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ func (r *TestResponse) Cookie(cookie contractshttp.Cookie) contractshttp.Context
panic("do not need to implement it")
}

func (r *TestResponse) Data(code int, contentType string, data []byte) contractshttp.ResponseWithAbort {
func (r *TestResponse) Data(code int, contentType string, data []byte) contractshttp.Response {
panic("do not need to implement it")
}

Expand All @@ -793,23 +793,23 @@ func (r *TestResponse) Header(key, value string) contractshttp.ContextResponse {
panic("do not need to implement it")
}

func (r *TestResponse) Json(code int, obj any) contractshttp.ResponseWithAbort {
func (r *TestResponse) Json(code int, obj any) contractshttp.Response {
panic("do not need to implement it")
}

func (r *TestResponse) NoContent(...int) contractshttp.ResponseWithAbort {
func (r *TestResponse) NoContent(...int) contractshttp.Response {
panic("do not need to implement it")
}

func (r *TestResponse) Origin() contractshttp.ResponseOrigin {
return &TestResponseOrigin{ctx: r}
}

func (r *TestResponse) Redirect(code int, location string) contractshttp.ResponseWithAbort {
func (r *TestResponse) Redirect(code int, location string) contractshttp.Response {
panic("do not need to implement it")
}

func (r *TestResponse) String(code int, format string, values ...any) contractshttp.ResponseWithAbort {
func (r *TestResponse) String(code int, format string, values ...any) contractshttp.Response {
panic("do not need to implement it")
}

Expand Down
122 changes: 0 additions & 122 deletions mocks/http/AbortResponse.go

This file was deleted.

Loading

0 comments on commit 57085e2

Please sign in to comment.