{"id":26924044,"url":"https://github.com/goiste/bit_flags","last_synced_at":"2025-04-02T01:53:05.558Z","repository":{"id":56855166,"uuid":"523050964","full_name":"goiste/bit_flags","owner":"goiste","description":"A simple package to store up to 64 boolean flags in one uint field","archived":false,"fork":false,"pushed_at":"2022-08-10T06:44:22.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-20T05:10:51.141Z","etag":null,"topics":["bitwise","boolean","flags","generics","go","golang","uint"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goiste.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-09T17:41:20.000Z","updated_at":"2024-06-20T05:10:51.143Z","dependencies_parsed_at":"2022-09-21T12:43:55.539Z","dependency_job_id":null,"html_url":"https://github.com/goiste/bit_flags","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goiste%2Fbit_flags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goiste%2Fbit_flags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goiste%2Fbit_flags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goiste%2Fbit_flags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goiste","download_url":"https://codeload.github.com/goiste/bit_flags/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246741161,"owners_count":20826063,"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":["bitwise","boolean","flags","generics","go","golang","uint"],"created_at":"2025-04-02T01:53:05.089Z","updated_at":"2025-04-02T01:53:05.551Z","avatar_url":"https://github.com/goiste.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bit Flags\n\nA simple package to store up to 64 boolean flags in one uint field.\n\nRequires Go version 1.18+ (uses generics)\n\nFor usage example see [example dir](example)\n\n```go\nimport (\n\t\"strings\"\n\n\tbf \"github.com/goiste/bit_flags\"\n)\n\nconst (\n\tMessages    = 1 \u003c\u003c iota // 1\n\tReplies                 // 2\n\tLikes                   // 4\n\tNewArticles             // ... powers of 2\n\tNews\n\n\tByEmail\n\tBySms\n\tByTelegram\n\n\tAllNotifications = Messages | Replies | Likes | NewArticles | News\n\tAllMethods       = ByEmail | BySms | ByTelegram\n)\n\ntype Notification struct {\n\tSomeOtherFields string\n\tFlags           bf.BitFlags[uint8]\n}\n\nfunc New() *Notification { ... }\n\nfunc (n *Notification) SetDefaultFlags() {\n\tn.Flags.Set(Messages | Replies | Likes | ByEmail)\n}\n\nfunc (n *Notification) SetAll() {\n\tn.Flags.Set(AllNotifications | AllMethods)\n}\n\nfunc (n *Notification) SetNone() {\n\tn.Flags.Reset()\n}\n\n...\n```\n[full notification.go](example/notification.go)\n```go\nfunc main() {\n\tntf := notification.New()\n\tfmt.Println(ntf.Flags.Get())     // 39\n\tfmt.Println(ntf.FlagsToString()) // Messages, Replies, Likes, By email\n\n\tntf.Flags.Add(notification.News | notification.BySms)\n\tntf.Flags.Remove(notification.Replies | notification.Likes)\n\tfmt.Println(ntf.FlagsToString())                // Messages, News, By email, By sms\n\tfmt.Println(ntf.HasFlag(notification.Messages)) // true\n\tfmt.Println(ntf.HasFlag(notification.Likes))    // false\n\n\tntf.Flags.Reset()\n\tfmt.Println(ntf.Flags.Get())     // 0\n\tfmt.Println(ntf.GetFlagsNames()) // []\n\n\tntf.SetAll()\n\tfmt.Println(ntf.Flags.Get())     // 255\n\tfmt.Println(ntf.FlagsToString()) // Messages, Replies, Likes, New articles, News, By email, By sms, By telegram\n}\n```\n[full main.go](example/main.go)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoiste%2Fbit_flags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoiste%2Fbit_flags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoiste%2Fbit_flags/lists"}