{"id":27134676,"url":"https://github.com/naya-team/flag","last_synced_at":"2025-06-17T23:37:49.561Z","repository":{"id":223623838,"uuid":"761035519","full_name":"naya-team/flag","owner":"naya-team","description":"flagger code for better release","archived":false,"fork":false,"pushed_at":"2024-02-21T07:11:06.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T00:49:09.460Z","etag":null,"topics":["go","golang","tbd"],"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/naya-team.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-21T05:42:59.000Z","updated_at":"2024-02-21T07:15:39.000Z","dependencies_parsed_at":"2024-02-21T08:24:22.207Z","dependency_job_id":"5079cee0-a2d7-49ff-9190-679ba27b47e4","html_url":"https://github.com/naya-team/flag","commit_stats":null,"previous_names":["naya-team/flag"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/naya-team/flag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naya-team%2Fflag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naya-team%2Fflag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naya-team%2Fflag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naya-team%2Fflag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naya-team","download_url":"https://codeload.github.com/naya-team/flag/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naya-team%2Fflag/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260458715,"owners_count":23012499,"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":["go","golang","tbd"],"created_at":"2025-04-08T00:49:11.568Z","updated_at":"2025-06-17T23:37:44.548Z","avatar_url":"https://github.com/naya-team.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flag\n\nthis package is used to flag some logic code or route if you don't want to publish on production environment. It's verry usefull if you use TBD (Trunk Based Development) and many people work on the same codebase.\n\nwith this package we can enable or disable some logic without redeploy application. so we expect to reduce the risk of deployment.\n\n## Dependencies\nits use goimports to format the code, so you need to install goimports first\n\n## Usage\n\n### On router\n\n```go\n\nfunc main(){\n    var db *sql.DB\n    var redis *redis.Client\n\n    _flag := flag.Init(db, redis)\n\n    mux := http.NewServeMux()\n    server.New(mux, _flag) // this outomaticly add flag to all route from flag\n\n}\n```\n\n#### to create flag\nPOST HOST/flag\nbody:\n```json\n{\n    \"flag\": \"some-flag\",\n    \"is_enable\": true\n}\n```\nif is_enable true. it will be active, if false it will be inactive\n\n#### to enable or disable flag\nPUT HOST/flag/:flag/:action\nparams\n* flag =\u003e name of flag, ex: some-flag\n* action =\u003e enable or disable\n\n#### to get all flag\nGET HOST/flags\n\n\n### On logic code\n\nif u want to flag some logic code, u can use flag like this:\n\n```go\n\nfunc SomeLogicFunc(){\n\tif flag.IsFlagged(\"someFlag\"){ \n\t\t// do something with active flag\n\t}else{ \n\t\t// do something with inactive flag \n\t}\n}\n```\n\nif u want to flag some route, u can use flag like this:\n\n`note: currently we only support http from standard library`\n\n```go\nhttp.HandleFunc(\"GET /some-route\", flag.ReleaseFlag(\"some-flag\", handler))\n```\n\n#### How to autoremoved flag ?\n\n1. build flag cli\n``` bash \ngo build -o flag cmd/flag/main.go\n```\n\n2. run flag cli\nAuto remove flag after one month\n```bash\n./flag erase --db-driver=\"postgres\" --dsn=\"postgres://postgres:postgres@localhost:5432/mydb?sslmode=disable\" --root-path=\".\"\n```\nor specific flag in our code\n```bash\n./flag erase --flags=\"some-flag,some-flag-2,some-flag-3\" --root-path=\".\" --db-driver=\"postgres\" --dsn=\"postgres://postgres:postgres@localhost:5432/mydb?sslmode=disable\"\n```\n`--db-driver` is driver of your database [mysql, postgres]\n\n`--dsn` is connection string to your database\n\n`--flags` is flags that you want to remove\n\n`--root-path` is path to your project\n\n    example: ./pkg/flag or \".\"\n    default value is \".\"\n\n\nhow to work, example file:\n\n```go\nfunc TestCoba123() {\n\n    var segmentation int\n    \n    if flag.IsEnable(\"some-flag\") {\n        fmt.Println(\"yeah....\")\n    }else{\n        fmt.Println(\"woooo.......\")\n    }\n    \n}\n```\n\nafter run command with arg `--flags=some-flag` should be\n```go\nfunc TestCoba123() {\n\n    var segmentation int\n\n\n    fmt.Println(\"yeah....\")\n\n\n    // some code\n}\n```\n\nor if code have negation\n``` go\nfunc TestCoba123() {\n\n    var segmentation int\n    \n    if !flag.IsEnable(\"some-flag\") {\n        fmt.Println(\"yeah....\")\n    }else{\n        fmt.Println(\"woooo.......\")\n    }\n    \n    // some code\n}\n```\nafter run code `--flags=some-flag` should be\n```go\nfunc TestCoba123() {\n\n    var segmentation int\n\n\n    fmt.Println(\"woooo.......\")\n\n\n    // some code\n}\n```\n\nor if on route middleware\n\nfrom\n\n```go\nhttp.HandleFunc(\"GET /some-route\", flag.ReleaseFlag(\"some-flag\", handler))\n```\nafter run should be\n``` go \nhttp.HandleFunc(\"GET /some-route\", handler)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaya-team%2Fflag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaya-team%2Fflag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaya-team%2Fflag/lists"}