chi-authz

chi-authz is an authorization middleware for Chi

Github星跟踪图

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.

主要指标

概览
名称与所有者casbin/chi-authz
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2023-09-17 18:35:21
推送于2024-01-29 15:58:59
最后一次提交2024-01-29 21:58:59
发布数0
用户参与
星数4
关注者数3
派生数3
提交数10
已启用问题?
问题数1
打开的问题数1
拉请求数1
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?