refactor: replace numeric literals with constants (#1)

Co-authored-by: Nagiyev Marif <marif.nagiyev@bcc.kz>
2 files changed
tree: 7a0f34b8e44b50a1c2142c3e995dd0beb61172d5
  1. .gitignore
  2. .travis.yml
  3. authz.go
  4. authz_model.conf
  5. authz_policy.csv
  6. authz_test.go
  7. LICENSE
  8. README.md
README.md

Chi-authz Coverage Status GoDoc

Chi-authz is an authorization middleware for Chi, it's based on https://github.com/casbin/casbin.

Installation

go get github.com/casbin/chi-authz

Simple Example

package main

import (
	"net/http"

	"github.com/casbin/chi-authz"
	"github.com/casbin/casbin"
	"github.com/go-chi/chi"
)

func main() {
	router := chi.NewRouter()

	// load the casbin model and policy from files, database is also supported.
	e := casbin.NewEnforcer("authz_model.conf", "authz_policy.csv")
	router.Use(authz.Authorizer(e))

	// define your handler, this is just an example to return HTTP 200 for any requests.
	// the access that is denied by authz will return HTTP 403 error.
	router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(200)
	})
}

Getting Help

License

This project is under MIT License. See the LICENSE file for the full license text.