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
用户参与
星數3
關注者數3
派生數3
提交數10
已啟用問題?
問題數1
打開的問題數1
拉請求數1
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?