feat:add context interface, and change core.writeresponse function to use it
This commit is contained in:
parent
321b4704a2
commit
4794137d42
5
internal/pkg/core/context.go
Normal file
5
internal/pkg/core/context.go
Normal file
@ -0,0 +1,5 @@
|
||||
package core
|
||||
|
||||
type Context interface {
|
||||
JSON(code int, obj any)
|
||||
}
|
@ -26,7 +26,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"git.vinchent.xyz/vinchent/howmuch/internal/pkg/errno"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ErrResponse struct {
|
||||
@ -36,7 +35,7 @@ type ErrResponse struct {
|
||||
|
||||
// WriteResponse writes the response to the HTTP response writer with HTTP code
|
||||
// and potential errors.
|
||||
func WriteResponse(c *gin.Context, err error, data any) {
|
||||
func WriteResponse(c Context, err error, data any) {
|
||||
// No error, write json response directly
|
||||
if err == nil {
|
||||
c.JSON(http.StatusOK, data)
|
||||
|
Loading…
Reference in New Issue
Block a user