https://github.com/arran4/gorillamuxlogic
Some very simple gorilla mux logic for `mux.MatcherFunc`
https://github.com/arran4/gorillamuxlogic
go golang gorilla gorilla-mux http web
Last synced: 21 days ago
JSON representation
Some very simple gorilla mux logic for `mux.MatcherFunc`
- Host: GitHub
- URL: https://github.com/arran4/gorillamuxlogic
- Owner: arran4
- License: mit
- Created: 2023-08-11T14:15:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-16T03:35:33.000Z (3 months ago)
- Last Synced: 2026-03-16T14:34:54.132Z (3 months ago)
- Topics: go, golang, gorilla, gorilla-mux, http, web
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Gorilla Mux Logic
Simple primitive enabling logic like this:
```go
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:
```go
func And(matchers ...mux.MatcherFunc) mux.MatcherFunc
func Or(matchers ...mux.MatcherFunc) mux.MatcherFunc
func Not(matcher mux.MatcherFunc) mux.MatcherFunc
```
Nested logic example:
```go
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](LICENSE).
## Installation
To add this package to your project, run:
```
go get github.com/arran4/gorillamuxlogic
```