mirror of
https://github.com/1f349/violet.git
synced 2024-11-21 10:51:40 +00:00
Output slice of values
This commit is contained in:
parent
eb8e4c7ed7
commit
b2a53722e6
@ -15,16 +15,13 @@ import (
|
||||
func SetupTargetApis(r *httprouter.Router, verify mjwt.Verifier, manager *router.Manager) {
|
||||
// Endpoint for routes
|
||||
r.GET("/route", checkAuthWithPerm(verify, "violet:route", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims) {
|
||||
routes, active, err := manager.GetAllRoutes()
|
||||
routes, err := manager.GetAllRoutes()
|
||||
if err != nil {
|
||||
apiError(rw, http.StatusInternalServerError, "Failed to get routes from database")
|
||||
return
|
||||
}
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
_ = json.NewEncoder(rw).Encode(map[string]any{
|
||||
"routes": routes,
|
||||
"active": active,
|
||||
})
|
||||
_ = json.NewEncoder(rw).Encode(routes)
|
||||
}))
|
||||
r.POST("/route", parseJsonAndCheckOwnership[routeSource](verify, "route", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims, t routeSource) {
|
||||
err := manager.InsertRoute(target.Route(t))
|
||||
@ -47,16 +44,13 @@ func SetupTargetApis(r *httprouter.Router, verify mjwt.Verifier, manager *router
|
||||
|
||||
// Endpoint for redirects
|
||||
r.GET("/redirect", checkAuthWithPerm(verify, "violet:redirect", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims) {
|
||||
redirects, active, err := manager.GetAllRedirects()
|
||||
redirects, err := manager.GetAllRedirects()
|
||||
if err != nil {
|
||||
apiError(rw, http.StatusInternalServerError, "Failed to get redirects from database")
|
||||
return
|
||||
}
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
_ = json.NewEncoder(rw).Encode(map[string]any{
|
||||
"redirects": redirects,
|
||||
"active": active,
|
||||
})
|
||||
_ = json.NewEncoder(rw).Encode(redirects)
|
||||
}))
|
||||
r.POST("/redirect", parseJsonAndCheckOwnership[redirectSource](verify, "redirect", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims, t redirectSource) {
|
||||
err := manager.InsertRedirect(target.Redirect(t))
|
||||
|
Loading…
Reference in New Issue
Block a user