mirror of
https://github.com/go-shiori/shiori.git
synced 2025-09-07 21:44:55 +08:00
* migrate bookmark content route to new http server * new archive page * remove unused go generate comment * database mock * utils cleanup * unused var * domains refactor and tests * fixed secret key type * redirect to login on ui errors * fixed archive folder with storage domain * webroot documentation * some bookmark route tests * fixed error in bookmark domain for non existant bookmarks * centralice errors * add coverage data to unittests * added tests, refactor storage to use afero * removed mock to avoid increasing complexity * using deps to copy files around * remove config usage (to deps) * remove handler-ui file
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package response
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
const internalServerErrorMessage = "Internal server error, please contact an administrator"
|
|
|
|
// New provides a shortcut to a successful response object
|
|
func New(ok bool, statusCode int, data interface{}) *Response {
|
|
return NewResponse(ok, data, nil, statusCode)
|
|
}
|
|
|
|
// Send provides a shortcut to send a (potentially) successful response
|
|
func Send(ctx *gin.Context, statusCode int, data interface{}) {
|
|
New(true, statusCode, data).Send(ctx)
|
|
}
|
|
|
|
// SendError provides a shortcut to send an unsuccessful response
|
|
func SendError(ctx *gin.Context, statusCode int, data interface{}) {
|
|
New(false, statusCode, data).Send(ctx)
|
|
}
|
|
|
|
// SendErrorWithParams the same as above but for errors that require error parameters
|
|
func SendErrorWithParams(ctx *gin.Context, statusCode int, data interface{}, errorParams map[string]string) {
|
|
NewResponse(false, data, errorParams, statusCode).Send(ctx)
|
|
}
|
|
|
|
// SendInternalServerError directly sends an internal server error response
|
|
func SendInternalServerError(ctx *gin.Context) {
|
|
SendError(ctx, http.StatusInternalServerError, internalServerErrorMessage)
|
|
}
|
|
|
|
// SendNotFound directly sends a not found response
|
|
func RedirectToLogin(ctx *gin.Context, dst string) {
|
|
ctx.Redirect(http.StatusFound, "/login?dst="+dst)
|
|
}
|
|
|
|
func NotFound(ctx *gin.Context) {
|
|
ctx.AbortWithStatus(http.StatusNotFound)
|
|
}
|