Commit 3261f2b6 authored by khoipham's avatar khoipham

add travis yaml

parent 38a27228
language: go
go:
- 1.12.x
- 1.13.x
env:
- PG_CONN=postgresql://postgres:@localhost:5432/postgres?sslmode=disable
services:
- postgresql
scripts: go test github.com/casbin/casbin-pg-adapter
...@@ -4,7 +4,7 @@ Go-pg Adapter is the [Go-pg](https://github.com/go-pg/pg) adapter for [Casbin](h ...@@ -4,7 +4,7 @@ Go-pg Adapter is the [Go-pg](https://github.com/go-pg/pg) adapter for [Casbin](h
## Installation ## Installation
go get github.com/pckhoi/casbin-pg-adapter go get github.com/casbin/casbin-pg-adapter
## Simple Postgres Example ## Simple Postgres Example
...@@ -12,9 +12,7 @@ Go-pg Adapter is the [Go-pg](https://github.com/go-pg/pg) adapter for [Casbin](h ...@@ -12,9 +12,7 @@ Go-pg Adapter is the [Go-pg](https://github.com/go-pg/pg) adapter for [Casbin](h
package main package main
import ( import (
"os" pgadapter "github.com/casbin/casbin-pg-adapter"
pgadapter "github.com/pckhoi/casbin-pg-adapter"
"github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2"
) )
...@@ -22,7 +20,7 @@ func main() { ...@@ -22,7 +20,7 @@ func main() {
// Initialize a Go-pg adapter and use it in a Casbin enforcer: // Initialize a Go-pg adapter and use it in a Casbin enforcer:
// The adapter will use the Postgres database named "casbin". // The adapter will use the Postgres database named "casbin".
// If it doesn't exist, the adapter will create it automatically. // If it doesn't exist, the adapter will create it automatically.
a, _ := pgadapter.NewAdapter(os.Getenv("PG_CONN")) // Your driver and data source. a, _ := pgadapter.NewAdapter("postgresql://username:password@postgres:5432/database?sslmode=disable") // Your driver and data source.
// Alternatively, you can construct an adapter instance with *pg.Options: // Alternatively, you can construct an adapter instance with *pg.Options:
// a, _ := pgadapter.NewAdapter(&pg.Options{ // a, _ := pgadapter.NewAdapter(&pg.Options{
// Database: "...", // Database: "...",
...@@ -59,14 +57,12 @@ You can [load a subset of policies](https://casbin.org/docs/en/policy-subset-loa ...@@ -59,14 +57,12 @@ You can [load a subset of policies](https://casbin.org/docs/en/policy-subset-loa
package main package main
import ( import (
"os"
"github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2"
pgadapter "github.com/pckhoi/casbin-pg-adapter" pgadapter "github.com/casbin/casbin-pg-adapter"
) )
func main() { func main() {
a, _ := pgadapter.NewAdapter(os.Getenv("PG_CONN")) a, _ := pgadapter.NewAdapter("postgresql://username:password@postgres:5432/database?sslmode=disable")
e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a) e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a)
e.LoadFilteredPolicy(&pgadapter.Filter{ e.LoadFilteredPolicy(&pgadapter.Filter{
...@@ -83,7 +79,7 @@ func main() { ...@@ -83,7 +79,7 @@ func main() {
## Debug tests ## Debug tests
docker-compose run --rm go dlv test github.com/pckhoi/casbin-pg-adapter docker-compose run --rm go dlv test github.com/casbin/casbin-pg-adapter
## Getting Help ## Getting Help
......
...@@ -22,7 +22,7 @@ services: ...@@ -22,7 +22,7 @@ services:
command: command:
- go - go
- test - test
- github.com/pckhoi/casbin-pg-adapter - github.com/casbin/casbin-pg-adapter
volumes: volumes:
gopkg: gopkg:
module github.com/pckhoi/casbin-pg-adapter module github.com/casbin/casbin-pg-adapter
go 1.12 go 1.12
......
package main package main
import ( import (
"os" pgadapter "github.com/casbin/casbin-pg-adapter"
"github.com/casbin/casbin/v2" "github.com/casbin/casbin/v2"
pgadapter "github.com/pckhoi/casbin-pg-adapter"
) )
func main() { func main() {
// Initialize a Go-pg adapter and use it in a Casbin enforcer: // Initialize a Go-pg adapter and use it in a Casbin enforcer:
// The adapter will use the Postgres database named "casbin". // The adapter will use the Postgres database named "casbin".
// If it doesn't exist, the adapter will create it automatically. // If it doesn't exist, the adapter will create it automatically.
a, _ := pgadapter.NewAdapter(os.Getenv("PG_CONN")) // Your driver and data source. a, _ := pgadapter.NewAdapter("postgresql://postgres:password@postgres:5432/postgres?sslmode=disable") // Your driver and data source.
// Alternatively, you can construct an adapter instance with *pg.Options: // Alternatively, you can construct an adapter instance with *pg.Options:
// a, _ := pgadapter.NewAdapter(&pg.Options{ // a, _ := pgadapter.NewAdapter(&pg.Options{
// Database: "...", // Database: "...",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment