Simple primitive enabling logic like this:
package main
import (
. "github.com/arran4/gorillamuxlogic"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.Use(UserMiddleware)
r.HandleFunc("/blog/{blog}/comment/{comment}/edit", blogsCommentEditPage).
MatcherFunc(Or(RequiredScopes("administrator"), CommentAuthor())).
Methods("POST")
}
Examples of runnable programs can be found under the examples/
directory.
Provides functions:
func And(matchers ...mux.MatcherFunc) mux.MatcherFunc
func Or(matchers ...mux.MatcherFunc) mux.MatcherFunc
func Not(matcher mux.MatcherFunc) mux.MatcherFunc
Nested logic example:
mux.NewRouter().
HandleFunc("/articles/{id}/edit", articleEditPage).
MatcherFunc(
Or(
And(RequiredScopes("administrator"), CommentAuthor()),
And(RequiredScopes("editor"), Not(CommentAuthor())),
),
).
Methods("POST")
This project is licensed under the MIT License.
To add this package to your project, run:
go get github.com/arran4/gorillamuxlogic