{"id":24883195,"url":"https://github.com/ajm188/go-ff","last_synced_at":"2025-03-27T09:16:05.185Z","repository":{"id":51074158,"uuid":"365508030","full_name":"ajm188/go-ff","owner":"ajm188","description":null,"archived":false,"fork":false,"pushed_at":"2021-05-26T14:00:41.000Z","size":3832,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-01T13:48:33.747Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ajm188.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":"2021-05-08T12:24:29.000Z","updated_at":"2021-09-18T11:35:32.000Z","dependencies_parsed_at":"2022-09-10T13:40:47.847Z","dependency_job_id":null,"html_url":"https://github.com/ajm188/go-ff","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/ajm188%2Fgo-ff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajm188%2Fgo-ff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajm188%2Fgo-ff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajm188%2Fgo-ff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajm188","download_url":"https://codeload.github.com/ajm188/go-ff/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245814749,"owners_count":20676808,"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":[],"created_at":"2025-02-01T13:48:35.853Z","updated_at":"2025-03-27T09:16:05.148Z","avatar_url":"https://github.com/ajm188.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-ff\n\nFeature flags in Go, backed by a grpc service.\n\nSurely not a bad idea.\n\n## Quickstart\n\n1. Build the server.\n\n    `$ go build -o server.bin ./cmd/server`\n1. Build the client.\n\n    `$ go build -o client.bin ./cmd/client`\n1. In one tab, run the server.\n\n    `$ ./server.bin`\n\n1. In a second tab, enable, disable, and remove features.\n\n```\n$ ./client.bin set foo constant --enabled\n$ ./client.bin set bar percentage_based -p10\n$ ./client.bin set baz expression -e\"1 \u003e 0\"\n$ ./client.bin list\nfoo:true\nbar:false\nbaz:false\n$ ./client.bin list -j | jq '.'\n{\n  \"bar\": {\n    \"name\": \"bar\",\n    \"type\": \"PERCENTAGE_BASED\",\n    \"percentage\": 10\n  },\n  \"baz\": {\n    \"name\": \"baz\",\n    \"type\": \"EXPRESSION\",\n    \"expression\": \"1 \u003e 0\"\n  },\n  \"foo\": {\n    \"name\": \"foo\",\n    \"type\": \"CONSTANT\",\n    \"enabled\": true\n  }\n}\n$ ./client.bin delete foo\ndeleted feature bar:true\n$ ./client.bin delete qux\nno such feature qux\n$ ./client.bin list -j | jq '.'\n{\n  \"bar\": {\n    \"name\": \"bar\",\n    \"type\": \"PERCENTAGE_BASED\",\n    \"percentage\": 10\n  },\n  \"baz\": {\n    \"name\": \"baz\",\n    \"type\": \"EXPRESSION\",\n    \"expression\": \"1 \u003e 0\"\n  }\n}\n```\n\n### Persistence\n\nThe feature server stores feature state in memory (for now). To get a modicum\nof persistence, you can use the client to dump out a JSON representation of the\nfeature map, and then use that file when restarting the server.\n\nFor example:\n\n```\nprompt1\u003e $ ./server.bin\nprompt2\u003e $ ./client.bin set foo constant --enabled\nprompt2\u003e $ ./client.bin set bar percentage_based -p10\nprompt2\u003e $ ./client.bin set baz expression -e\"1 \u003e 0\"\nprompt2\u003e $ ./client.bin list -j \u003e feature_flags.json\nprompt1\u003e $ ./server.bin --config feature_flags.json\nprompt2\u003e $ ./client.bin list -j\n{\n  \"bar\": {\n    \"name\": \"bar\",\n    \"type\": \"PERCENTAGE_BASED\",\n    \"percentage\": 10\n  },\n  \"baz\": {\n    \"name\": \"baz\",\n    \"type\": \"EXPRESSION\",\n    \"expression\": \"1 \u003e 0\"\n  },\n  \"foo\": {\n    \"name\": \"foo\",\n    \"type\": \"CONSTANT\",\n    \"enabled\": true\n  }\n}\n```\n\n### In your code\n\n```go\nimport \"github.com/ajm188/go-ff/feature\"\n\n// Initialization code\nfunc init() {\n    if err := feature.InitFromFile(\"/path/to/feature_flags.json\"); err != nil {\n        panic(err)\n    }\n}\n\nfunc SomeFunction() {\n    enabled, err := feature.Get(\"name_of_my_feature\", nil)\n    if err != nil {\n        // handle error\n    }\n\n    if enabled {\n        DoNewThing()\n    } else {\n        DoOldThing()\n    }\n}\n\nfunc SomeFunctionWithParameters(name string) {\n    enabled, err := feature.Get(\"another_feature\", map[string]interface{\n        \"name\": name,\n    })\n    if err != nil {\n        // handle error\n    }\n\n    if enabled {\n        DoNewThing()\n    } else {\n        DoOldThing()\n    }\n}\n```\n\nFor dynamic modification of feature flags, you would also want to run a gRPC\nserver that has the FeaturesServer service running, e.g.:\n\n```go\nimport (\n    \"github.com/ajm188/go-ff/feature\"\n    \"google.golang.org/grpc\"\n)\n\nfunc run() {\n    s := grpc.NewServer()\n    feature.RegisterServer(s)\n\n    // Register your other services on `s`.\n\n    go s.Serve(lis)\n}\n```\n\nAnd now you can use the client, as in the [quickstart](#Quickstart), to add,\nmodify, and remove features from your code at runtime.\n\nFor more advanced production uses, you will want to run the FeatureServer gRPC\nservice on a separate port to restrict access to administrators and operators\nof your service (i.e. you should not have \"feature flag admin\" on the same port\nas your actual application rpcs).\n\n## Development\n\n1. [Install protoc](https://grpc.io/docs/protoc-installation/).\n\n1. Install latest `protoc-gen-gofast`.\n\n    `$ go install github.com/gogo/protobuf/protoc-gen-gofast@latest`\n\n1. If changing anything in `./proto/*.proto`, re-generate the generated Go code.\n\n    `$ make proto`\n\n## \"Roadmap\"\n\nSee our [issue tracker](https://github.com/ajm188/go-ff/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajm188%2Fgo-ff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajm188%2Fgo-ff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajm188%2Fgo-ff/lists"}