gin/araneae_response.go

79 lines
1.6 KiB
Go
Raw Normal View History

package gin
import (
"net/http"
)
type IResponse interface {
IJSON(status int, obj any) IResponse
IXML(status int, obj any) IResponse
IHTML(status int, filepath string, obj any) IResponse
IText(status int, format string, values ...any) IResponse
IRedirect(status int, path string) IResponse
ISetHeader(key string, val string) IResponse
ISetCookie(
key string,
val string,
maxAge int,
path, domain string,
secure, httpOnly bool,
) IResponse
ISetStatus(code int) IResponse
// set 200
ISetOKStatus() IResponse
}
func (ctx *Context) IJSON(status int, obj any) IResponse {
ctx.JSON(status, obj)
return ctx
}
func (ctx *Context) IXML(status int, obj any) IResponse {
ctx.XML(status, obj)
return ctx
}
func (ctx *Context) IHTML(status int, filepath string, obj any) IResponse {
ctx.HTML(status, filepath, obj)
return ctx
}
func (ctx *Context) IText(status int, format string, values ...any) IResponse {
ctx.String(status, format, values...)
return ctx
}
func (ctx *Context) IRedirect(status int, path string) IResponse {
ctx.Redirect(status, path)
return ctx
}
func (ctx *Context) ISetHeader(key string, val string) IResponse {
ctx.Header(key, val)
return ctx
}
func (ctx *Context) ISetCookie(
key string,
val string,
maxAge int,
path, domain string,
secure, httpOnly bool,
) IResponse {
ctx.SetCookie(key, val, maxAge, path, domain, secure, httpOnly)
return ctx
}
func (ctx *Context) ISetStatus(code int) IResponse {
ctx.Status(code)
return ctx
}
// set 200
func (ctx *Context) ISetOKStatus() IResponse {
ctx.Status(http.StatusOK)
return ctx
}