{"id":21395159,"url":"https://github.com/gabrielhora/goth","last_synced_at":"2025-03-16T14:25:37.126Z","repository":{"id":57545780,"uuid":"298413009","full_name":"gabrielhora/goth","owner":"gabrielhora","description":"Simple authorization for http.Handler","archived":false,"fork":false,"pushed_at":"2020-09-26T18:23:02.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T01:44:09.715Z","etag":null,"topics":["authorization","go"],"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/gabrielhora.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-09-24T22:55:04.000Z","updated_at":"2020-09-27T09:10:01.000Z","dependencies_parsed_at":"2022-09-05T12:31:02.898Z","dependency_job_id":null,"html_url":"https://github.com/gabrielhora/goth","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/gabrielhora%2Fgoth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielhora%2Fgoth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielhora%2Fgoth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielhora%2Fgoth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabrielhora","download_url":"https://codeload.github.com/gabrielhora/goth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243880565,"owners_count":20362792,"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":["authorization","go"],"created_at":"2024-11-22T14:18:27.692Z","updated_at":"2025-03-16T14:25:37.101Z","avatar_url":"https://github.com/gabrielhora.png","language":"Go","readme":"# Goth (wip)\n\nCentrally define authorization rules for your HTTP handlers.\n\nExample:\n\n```go\nfunc main() {\n    mux := http.NewServeMux()\n    mux.HandleFunc(\"/\", func(w http.ResponseWriter, req *http.Request) {\n        _, _ = fmt.Fprint(w, \"index\")\n    })\n\n    mux.HandleFunc(\"/admin/\", func(w http.ResponseWriter, req *http.Request) {\n        _, _ = fmt.Fprint(w, \"admin\")\n    })\n\n    mux.HandleFunc(\"/login\", func(w http.ResponseWriter, req *http.Request) {\n        _, _ = fmt.Fprint(w, \"login\")\n    })\n\n    g := goth.New(mux, auth)\n    g.LoginURL(\"/login\")\n    \n    // anything inside /admin requires \"admin\" or \"staff\" roles\n    g.Rule(\"/admin/?(.*)\", \"admin,staff\")\n    \n    // anything else allow any user\n    g.Rule(\"/?(.*)\", \"annon\")\n\n    server := http.Server{\n        Addr:    \":8080\",\n        Handler: g,\n    }\n\n    _ = server.ListenAndServe()\n}\n\n// this function should return the current user and it's roles, you are\n// free to choose how to get this info (from session, cookie, header, etc)\nfunc auth(req *http.Request) (user interface{}, roles []string, err error) {\n    return 1, []string{\"user\"}, nil\n}\n``` \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielhora%2Fgoth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrielhora%2Fgoth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielhora%2Fgoth/lists"}