chi-authz

chi-authz is an authorization middleware for Chi

Github stars Tracking Chart

Chi-authz Build Status 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.

Main metrics

Overview
Name With Ownercasbin/chi-authz
Primary LanguageGo
Program languageGo (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2023-09-17 18:35:21
Pushed At2024-01-29 15:58:59
Last Commit At2024-01-29 21:58:59
Release Count0
用户参与
Stargazers Count3
Watchers Count3
Fork Count3
Commits Count10
Has Issues Enabled
Issues Count1
Issue Open Count1
Pull Requests Count1
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private