https://github.com/permify/permify-go
Permify Go Client
https://github.com/permify/permify-go
Last synced: 2 months ago
JSON representation
Permify Go Client
- Host: GitHub
- URL: https://github.com/permify/permify-go
- Owner: Permify
- License: apache-2.0
- Created: 2023-01-10T16:18:08.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-09T08:39:05.000Z (3 months ago)
- Last Synced: 2025-04-09T09:36:18.056Z (3 months ago)
- Language: Go
- Size: 640 KB
- Stars: 24
- Watchers: 2
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
![]()
Permify Golang Client# Installation
```shell
go get buf.build/gen/go/permifyco/permify/protocolbuffers/go/base/v1
go get github.com/Permify/permify-go
```# How to use
### Import Permify.
```go
import (
permify_payload "buf.build/gen/go/permifyco/permify/protocolbuffers/go/base/v1"
permify_grpc "github.com/Permify/permify-go/grpc"
)
```### Initialize the new Permify client.
```go
// generate new client
client, err := permify_grpc.NewClient(
permify_grpc.Config{
Endpoint: `localhost:3478`,
},
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
```### Create a new tenant
```go
ct, err := client.Tenancy.Create(context.Background(), &permify_payload.TenantCreateRequest{
Id: "t1",
Name: "tenant 1",
})
```### Write Schema
```go
sr, err: = client.Schema.Write(context.Background(), &permify_payload.SchemaWriteRequest {
TenantId: "t1",
Schema: `
entity user {}
entity document {
relation viewer @user
action view = viewer
}`,
})
```### Write Relationships
```go
rr, err := client.Data.WriteRelationships(context.Background(), & permify_payload.RelationshipWriteRequest {
TenantId: "t1",
Metadata: & permify_payload.RelationshipWriteRequestMetadata {
SchemaVersion: sr.SchemaVersion, // sr --> schema write response
},
Tuples: [] * permify_payload.Tuple {
{
Entity: & permify_payload.Entity {
Type: "document",
Id: "1",
},
Relation: "viewer",
Subject: & permify_payload.Subject {
Type: "user",
Id: "1",
},
}, {
Entity: & permify_payload.Entity {
Type: "document",
Id: "3",
},
Relation: "viewer",
Subject: & permify_payload.Subject {
Type: "user",
Id: "1",
},
}
},
})
```### Check
```go
cr, err := client.Permission.Check(context.Background(), & permify_payload.PermissionCheckRequest {
TenantId: "t1",
Metadata: & permify_payload.PermissionCheckRequestMetadata {
SnapToken: rr.SnapToken, // rr --> relationship write response
SchemaVersion: sr.SchemaVersion, // sr --> schema write response
Depth: 50,
},
Entity: & permify_payload.Entity {
Type: "document",
Id: "1",
},
Permission: "view",
Subject: & permify_payload.Subject {
Type: "user",
Id: "3",
},
})if (cr.can == PermissionCheckResponse_Result.RESULT_ALLOWED) {
// RESULT_ALLOWED
} else {
// RESULT_DENIED
}
```### Streaming Calls
```go
str, err := client.Permission.LookupEntityStream(context.Background(), & permify_payload.PermissionLookupEntityRequest {
TenantId: "t1",
Metadata: & permify_payload.PermissionLookupEntityRequestMetadata {
SnapToken: rr.SnapToken, // rr --> relationship write response
SchemaVersion: sr.SchemaVersion, // sr --> schema write response
Depth: 50,
},
EntityType: "document",
Permission: "view",
Subject: & permify_payload.Subject {
Type: "user",
Id: "1",
},
})// handle stream response
for {
res, err: = str.Recv()if err == io.EOF {
break
}// res.EntityId
}
```Permify is an **open-source authorization service** for creating and maintaining fine-grained authorizations across your individual applications and services.
* [Permify website](https://permify.co)
* [Permify documentation](https://docs.permify.co/docs/)
* [Permify playground](https://play.permify.co)
* [Permify GitHub Repository](https://github.com/Permify/permify)## Community & Support
Join our [Discord channel](https://discord.gg/MJbUjwskdH) for issues, feature requests, feedbacks or anything else. We love to talk about authorization and access control :heart: