Skip to content

yclw/gf-casbin-adapter

Repository files navigation

GF Casbin Adapter

Go GoFrame Casbin

English | 中文

A Casbin adapter based on the GoFrame framework. With this library, Casbin can load policies from or save policies to databases supported by GoFrame. This adapter supports or plans to support all Casbin adapter interfaces.

Based on GoFrame database driver support, currently supported databases include:

  • MySQL
  • PostgreSQL
  • Other databases supported by GoFrame

Both model and dao are generated by gf gen, conforming to GoFrame's ORM specifications.

Features

  • This adapter implements all Casbin Adapter interfaces, but functionality is still being tested.

Quick Start

Please complete GoFrame database configuration first and import relevant driver packages, such as: import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"

Installation

go get github.com/yclw/gf-casbin-adapter

Import

import (
 gfadapter "github.com/yclw/gf-casbin-adapter"
 "github.com/casbin/casbin/v2"
 "github.com/casbin/casbin/v2/model"
)

Create Adapter

// Create Adapter
adapter, err := gfadapter.NewAdapter()

Create Enforcer

// Create model according to Casbin requirements

// Create enforcer using model and adapter
enforcer, err := casbin.NewEnforcer(model, adapter)

Notes

  1. Ensure GoFrame database configuration is correct.

Database Table Structure

CREATE TABLE casbin_rule (
    id    BIGINT AUTO_INCREMENT PRIMARY KEY,
    ptype VARCHAR(100) DEFAULT '' NOT NULL,
    v0    VARCHAR(100) DEFAULT '' NOT NULL,
    v1    VARCHAR(100) DEFAULT '' NOT NULL,
    v2    VARCHAR(100) DEFAULT '' NOT NULL,
    v3    VARCHAR(100) DEFAULT '' NOT NULL,
    v4    VARCHAR(100) DEFAULT '' NOT NULL,
    v5    VARCHAR(100) DEFAULT '' NOT NULL,
    INDEX idx_ptype (ptype),
    INDEX idx_v0 (v0),
    INDEX idx_v1 (v1),
    INDEX idx_v2 (v2),
    INDEX idx_v3 (v3),
    INDEX idx_v4 (v4),
    INDEX idx_v5 (v5),
) COMMENT 'Casbin';

Getting Help

License

This project is licensed under the Apache 2.0 License. See the LICENSE file for details.

Contributing

Issues and Pull Requests are welcome to improve this project.

About

A Casbin adapter based on the GoFrame framework. With this library, Casbin can load policies from or save policies to databases supported by GoFrame. This adapter supports or plans to support all Casbin adapter interfaces.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages