Esempio n. 1
0
func main() {
	permission := gopermission.New(HasQwertyHeader{})
	qwertyMiddleware := func(c *echo.Context) error {
		if !permission.IsPermitted(c.Request()) {
			c.String(403, "Error")
			return echo.NewHTTPError(http.StatusUnauthorized)
		}
		return nil
	}

	echo := echo.New()
	echo.Use(qwertyMiddleware)
	echo.Get("/", handler)
	echo.Run(":9090")
}
Esempio n. 2
0
func main() {
	permission := gopermission.New(HasQwertyHeader{})
	qwertyMiddleware := func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if !permission.IsPermitted(r) {
				w.Write([]byte("Error"))
				return
			}
			next.ServeHTTP(w, r)
		})
	}

	http.Handle("/", qwertyMiddleware(http.HandlerFunc(
		func(w http.ResponseWriter, r *http.Request) {
			w.Write([]byte("Granted"))
		}),
	))
	http.ListenAndServe(":9090", nil)
}