{"id":20666264,"url":"https://github.com/rezaoptic/go-utils","last_synced_at":"2026-06-06T15:01:53.443Z","repository":{"id":57541834,"uuid":"290761468","full_name":"RezaOptic/go-utils","owner":"RezaOptic","description":"some utils for Go projects.","archived":false,"fork":false,"pushed_at":"2020-10-01T16:27:14.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-17T12:57:55.091Z","etag":null,"topics":["authentication","error-handling","go","go-package","hacktoberfest","jwt","logger","multi-language","utils"],"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/RezaOptic.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}},"created_at":"2020-08-27T11:49:49.000Z","updated_at":"2020-10-14T12:16:16.000Z","dependencies_parsed_at":"2022-09-10T04:05:07.348Z","dependency_job_id":null,"html_url":"https://github.com/RezaOptic/go-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RezaOptic%2Fgo-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RezaOptic%2Fgo-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RezaOptic%2Fgo-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RezaOptic%2Fgo-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RezaOptic","download_url":"https://codeload.github.com/RezaOptic/go-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242855157,"owners_count":20196353,"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","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":["authentication","error-handling","go","go-package","hacktoberfest","jwt","logger","multi-language","utils"],"created_at":"2024-11-16T19:36:20.672Z","updated_at":"2025-03-10T12:52:47.663Z","avatar_url":"https://github.com/RezaOptic.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-utils\n\nThis is utils for Go project.\n\n## auth:\na package for generate and validate access token.\naccess token contains the following structure.\n```go\nUserID   interface{}\nUsername *string    \nAppID    *string    \nEmail    *string    \nStatus   *string    \nRoles    []string   \n``` \n\n### Usage:\n\n---\n\n### Initialize:\n\nImport it in your code:\n\n```go\nimport \"github.com/RezaOptic/go-utils/auth\"\n```\n\nat the first, we need to initialize the package for configs.\n```go\nauth.Init(ACCESS_TOKEN_SECRET, EXPIRE_TIME_IN_SECOND)\n```\n\n### Generate token:\n```go\nuserClaim := auth.UserClaims{UserID: UserID}\nToken, err := userClaim.Token()\nif err != nil {\n\tpanic(err)\n}\nfmt.Println(Token)\n```\n\n### Validate token:\n\n#### **ginMiddleware**:\n\n for adding protection to your route add gin Middleware like this:\n ```go\n Foo.GET(\"/foo/user/:user_id\", auth.JwtAuth(BarController, SELF_ACCESS, OPTIONAL, ROLES))\n ```\n and in your `BarController` can get user token information like this:\n ```go\n UserTokenInfotmation := auth.GetClaimFromContext(c)\n ```\n\n `SELF_ACCESS`: if you have `:user_id` param in your path for authorization TokenUserID and `user_id` must be the same.\n\n `OPTIONAL`: if you set this flag to true sending `Authorization` in the header is optional and if you don't send the token `auth.GetClaimFromContext(c)` return an empty struct.\n\n `ROLES`: roles is an array of string token must include these roles.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frezaoptic%2Fgo-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frezaoptic%2Fgo-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frezaoptic%2Fgo-utils/lists"}