Skip to content

arran4/gorillamuxlogic

Repository files navigation

Gorilla Mux Logic

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")

License

This project is licensed under the MIT License.

Installation

To add this package to your project, run:

go get github.com/arran4/gorillamuxlogic

About

Some very simple gorilla mux logic for `mux.MatcherFunc`

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages