Add auth, rest api, svelte frontend, build structure
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RecoverMiddleware(next http.Handler) http.Handler {
|
||||
func Recover(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
|
27
internal/middleware/securedCheck.go
Normal file
27
internal/middleware/securedCheck.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.clustercockpit.org/moebiusband/go-http-skeleton/internal/auth"
|
||||
"git.clustercockpit.org/moebiusband/go-http-skeleton/web"
|
||||
)
|
||||
|
||||
func SecuredCheck(next http.Handler) http.Handler {
|
||||
authHandle := auth.GetAuthInstance()
|
||||
|
||||
return authHandle.Auth(
|
||||
// On success;
|
||||
next,
|
||||
|
||||
// On failure:
|
||||
func(rw http.ResponseWriter, r *http.Request, err error) {
|
||||
rw.WriteHeader(http.StatusUnauthorized)
|
||||
web.RenderTemplate(rw, "login", web.PageData{
|
||||
Title: "Authentication failed - ClusterCockpit",
|
||||
MsgType: "alert-danger",
|
||||
Message: err.Error(),
|
||||
Redirect: r.RequestURI,
|
||||
})
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user