{"id":28028405,"url":"https://github.com/permitio/permit-go-example","last_synced_at":"2025-10-05T20:11:42.864Z","repository":{"id":224916818,"uuid":"760363449","full_name":"permitio/permit-go-example","owner":"permitio","description":"An example of Permit.io-based authorization for Go","archived":false,"fork":false,"pushed_at":"2024-02-26T12:21:47.000Z","size":272,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-02T09:36:05.502Z","etag":null,"topics":["example"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/permitio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-20T09:28:50.000Z","updated_at":"2025-03-13T15:22:43.000Z","dependencies_parsed_at":"2024-02-28T12:01:17.917Z","dependency_job_id":null,"html_url":"https://github.com/permitio/permit-go-example","commit_stats":null,"previous_names":["permitio/permit-go-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/permitio/permit-go-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-go-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-go-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-go-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-go-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/permitio","download_url":"https://codeload.github.com/permitio/permit-go-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-go-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278510931,"owners_count":25999005,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example"],"created_at":"2025-05-11T07:13:35.560Z","updated_at":"2025-10-05T20:11:42.843Z","avatar_url":"https://github.com/permitio.png","language":"Go","readme":"# Permit.io Go application example\n\n##  Prerequisites\n\n- [Terraform](https://developer.hashicorp.com/terraform/downloads) \u003e= 1.0\n- [Go](https://golang.org/doc/install) \u003e= 1.19\n\n### init\n\nFrom the application folder:\n\n```sh\ngo mod tidy\ngo run main.go\n```\n\nThe app server will listen on port 8080\nYou can reach out and verify it is up and running: http://localhost:8080/\n\n### PDP installation\nPDP is the component that will enforcement the policies and on every permit.check command will contact with permit.io to check policies and data configuration.\nIn order to run it, please run the following Docker command:\n\n```sh\ndocker run -p 7766:7000 --env PDP_API_KEY=\u003cAPI_KEY\u003e --env PDP_DEBUG=true permitio/pdp-v2:latest\n```\nThe PDP will run internally on port 7000 and will export port 7766 outside\n\nThe PDP configure at the app will looks like the following:\n\n```go\npermitConfig := config.NewConfigBuilder(\n\t\t\"\u003cAPI_KEY\u003e\").\n\t\tWithPdpUrl(\"http://localhost:7766\").\n\t\tBuild()\n```\nIn order to make sure that the PDP is up and running, please look at logs, for example:\n\n2024-02-22 08:50:22.147 | 29514 | INFO     | opal_client.opa.logger:log_entire_dict:89 - Logs uploaded successfully. {\"plugin\": \"decision_logs\", \"time\": \"2024-02-22T08:50:22Z\"}\n\n### Configure terraform provider\n```hcl\nterraform {\n  required_providers {\n    permitio = {\n      source  = \"permitio/permit-io\"\n      version = \"~\u003e 0.0.1\"\n    }\n  }\n}\n\nprovider \"permitio\" {\n    api_url = \"https://api.permit.io\" # Defaults to - \"https://api.permit.io - Can be set as an environment variable PERMITIO_API_URL\n    api_key = \"YOUR_API_KEY\" # Can be set as an environment variable PERMITIO_API_KEY\n}\n```\n\nNow please run the terraform file in order to create the policies and roles:\n\n```sh\nterraform init\nterraform plan\nterraform apply\n```\nExample screenshots of the expected state after terraform apply:\n\n![Screenshot](images/roles.png)\n![Screenshot](images/editor.png)\n![Screenshot](images/owner.png)\n![Screenshot](images/pu.png)\n![Screenshot](images/viewer.png)\n\nAll Set! Go to permit.io to 'Policy' tab and verify that policies and roles are there and fill them according to your wish.\nIf so, lets begin! open terminal:\n\n```sh\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"name\": \"permit1\"}' http://localhost:8080/signup\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"name\": \"permit2\"}' http://localhost:8080/signup\ncurl -X POST -H \"Content-Type: application/json\" -d '{\"name\": \"permit3\"}' http://localhost:8080/signup\n```\nNow go to Permit.io and check under 'Directory' tab that you able to see all the new users, if you're not see them please verify that you're on 'All Tenants' and not under 'Default Tenant'.\n\nHere are few curl commands in order to check the policy enforcement:\n\n## Request:\n```sh\ncurl -X POST -d '{\"user_name\":\"permit1\",\"name\":\"My_New_Blog\"}' http://localhost:8080/blogs\n```\n## Response:\n'New blog created successfully' for success\n'Access denied' for unsuccess\n\n## Request:\n```sh\ncurl -X DELETE -d '{\"user_name\":\"permit1\"}' http://localhost:8080/blogs/permit_blog1\n```\n## Response:\n'Blog with ID permit_blog1 deleted successfully' for success\n'Access denied' for unsuccess\n\n\n## Request:\n```sh\ncurl -X GET -d '{\"user_name\":\"permit2\"}' http://localhost:8080/blogs\n```\n## Response:\n'[\"blog1\",\"blog2\",\"blog3\"]' for success\n'Access denied' for unsuccess\n\n\n## Request:\n```sh\ncurl -X POST -d '{\"user_name\":\"permit3\"}' http://localhost:8080/transfer_payment_for_blog\n```\n## Response:\n'Payment transferred successfully for blog' for success\n'Access denied' for unsuccess\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermitio%2Fpermit-go-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpermitio%2Fpermit-go-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermitio%2Fpermit-go-example/lists"}