{"id":18832583,"url":"https://github.com/linka-cloud/protoc-gen-defaults","last_synced_at":"2025-08-31T04:07:22.052Z","repository":{"id":57615785,"uuid":"382664160","full_name":"linka-cloud/protoc-gen-defaults","owner":"linka-cloud","description":"A Protobuf Plugin fo Golang generating Default for message.","archived":false,"fork":false,"pushed_at":"2024-10-22T06:56:40.000Z","size":190,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T04:36:30.651Z","etag":null,"topics":["default","default-method","defaults","golang","protobuf","protoc"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linka-cloud.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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-07-03T16:40:25.000Z","updated_at":"2025-02-12T14:19:50.000Z","dependencies_parsed_at":"2024-10-22T16:14:49.989Z","dependency_job_id":null,"html_url":"https://github.com/linka-cloud/protoc-gen-defaults","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"c8e977fb8a2d86e2a96247028cc500deef76df66"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/linka-cloud/protoc-gen-defaults","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fprotoc-gen-defaults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fprotoc-gen-defaults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fprotoc-gen-defaults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fprotoc-gen-defaults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linka-cloud","download_url":"https://codeload.github.com/linka-cloud/protoc-gen-defaults/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Fprotoc-gen-defaults/sbom","scorecard":{"id":590902,"data":{"date":"2025-08-11","repo":{"name":"github.com/linka-cloud/protoc-gen-defaults","commit":"1b81061d20ceced5dd107b1020802817e23b245d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/10 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENCE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENCE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":8,"reason":"2 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2024-2611 / GHSA-8r3f-844c-mc37","Warn: Project is vulnerable to: GO-2022-0603 / GHSA-hp87-p4gw-j4gq"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T21:51:46.744Z","repository_id":57615785,"created_at":"2025-08-20T21:51:46.744Z","updated_at":"2025-08-20T21:51:46.744Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272936434,"owners_count":25018164,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["default","default-method","defaults","golang","protobuf","protoc"],"created_at":"2024-11-08T01:58:18.163Z","updated_at":"2025-08-31T04:07:22.034Z","avatar_url":"https://github.com/linka-cloud.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# protoc-gen-defaults\n\n*This project is currently in **alpha**. The API should be considered unstable and likely to change*\n\n**protoc-gen-defaults** is a protoc plugin generating the implementation of a `Defaulter` \ninterface on messages:\n```go\ntype Defaulter interface {\n\tDefault()\n}\n```\n\n## Installation\n\n```bash\ngo get go.linka.cloud/protoc-gen-defaults\n```\n\n## Usage\n\n### Overview\n\n**protoc-gen-defaults** make use of **Protobuf** options to define defaults field value.\n\n### Generation\n\n**protoc-gen-defaults** works the same way does the **protoc** plugins\n\nExample:\n```bash\nprotoc -I. -I defaults --go_out=paths=source_relative:. --defaults_out=paths=source_relative:. types.proto\n```\n\n### Disable generation or implementation\n\nImplementation generation can be ignored with the `(defaults.ignored) = true` message option.\n\n```proto\nmessage NoDefaulterImplementation {\n\toption (defaults.ignored) = true;\n\tstring string_field = 1 [(defaults.value).string = \"string_field\"];\n}\n```\n\u003e It may be useful if you intend to write your own `Defaulter` implementation.\n\n\nAn empty implementation can be generated with the `(defaults.disabled) = true` message option\n\n```proto\nmessage EmptyDefaulterImplementation {\n    option (defaults.disabled) = true;\n    string string_field = 1 [(defaults.value).string = \"string_field\"];\n}\n```\n\n### Scalar and Well-Known Value\n\nEach scalar or Well-Known type has its corresponding `(defaults.value).[scalar] = [value]` option, \nthe `[value]` will be set if the scalar field has the **zero value**, e.g `0` for numbers, \n`\"\"` for strings, `false` for bools\n\n- **float / google.protobuf.FloatValue**:\n    ```proto\n    float float = 1 [(defaults.value).float = 0.42];\n    ```\n- **double / google.protobuf.DoubleValue**: \n    ```proto \n    double double = 2 [(defaults.value).double = 0.42];\n    ****google.protobuf.DoubleValue double_value = 20 [(defaults.value).double = 0.42];\n    ```\n- **int32 / google.protobuf.Int32Value**: \n    ```proto  \n    int32 int32 = 3 [(defaults.value).int32 = 42];\n    google.protobuf.Int32Value int32_value = 24 [(defaults.value).int32 = 42];\n    ```\n- **int64 / google.protobuf.Int64Value**: \n    ```proto  \n    int64 int64 = 4 [(defaults.value).int64 = 42];\n    google.protobuf.Int64Value int64_value = 22 [(defaults.value).int64 = 42];\n    ```\n- **uint32 / google.protobuf.UInt32Value**: \n    ```proto  \n    uint32 uint32 = 5 [(defaults.value).uint32 = 42];\n    google.protobuf.UInt32Value uint32_value = 25 [(defaults.value).uint32 = 42];\n    ```\n- **uint64 / google.protobuf.UInt64Value**: \n    ```proto  \n    uint64 uint64 = 6 [(defaults.value).uint64 = 42];\n    google.protobuf.UInt64Value uint64_value = 23 [(defaults.value).uint64 = 42];\n    ```\n- **sint32**: \n    ```proto  \n    sint32 sint32 = 7 [(defaults.value).sint32 = 42];\n    ```\n- **sint64**: \n    ```proto  \n    sint64 sint64 = 8 [(defaults.value).sint64 = 42];\n    ```\n- **fixed32**: \n    ```proto  \n    fixed32 fixed32 = 9 [(defaults.value).fixed32 = 42];\n    ```\n- **fixed64**: \n    ```proto  \n    fixed64 fixed64 = 10 [(defaults.value).fixed64 = 42];\n    ```\n- **sfixed32**: \n    ```proto  \n    sfixed32 sfixed32 = 11 [(defaults.value).sfixed32 = 42];\n    ```\n- **sfixed64**: \n    ```proto  \n    sfixed64 sfixed64 = 12 [(defaults.value).sfixed64 = 42];\n    ```\n- **bool / google.protobuf.BoolValue**: \n    ```proto  \n    bool bool = 13 [(defaults.value).bool = true];\n    google.protobuf.BoolValue bool_value = 26 [(defaults.value).bool = false];\n    ```\n- **string / google.protobuf.StringValue**: \n    ```proto  \n    string string = 14 [(defaults.value).string = \"42\"];\n    google.protobuf.StringValue string_value = 27 [(defaults.value).string = \"42\"];\n    ```\n- **bytes / google.protobuf.BytesValue**: \n    ```proto  \n    bytes bytes = 15 [(defaults.value).bytes = \"42\"];\n    google.protobuf.BytesValue bytes_value = 28 [(defaults.value).bytes = \"42\"];\n    ```\n    \n### Messages \n\nMessage default behaviour is defined with the `(defaults.value).message = {initialize: bool, defaults: bool}` field option.\n\n- `initialize`: if set to `true` the field will be initialized with an empty `stuct reference` from the appropriate type\n- `defaults`: tells that the `Default` method should be called if the type implements the `Defaulter` interface\n\n```proto\nMessage message = 17 [(defaults.value).message = {initialize: true, defaults: true}];\n```\n\n### Well-Known Messages\n\n**google.protobuf.Duration** \n  \nThe default value is parsed according to the [Prometheus time durations format](https://prometheus.io/docs/prometheus/latest/querying/basics/#time-durations)\n```proto\ngoogle.protobuf.Duration duration = 18 [(defaults.value).duration = \"2d\"];\n```\n\n**google.protobuf.Timestamp**\n\nThe default value is parsed using the following RFCs as defined in the `time` package:\n  - time.RFC822\n  - time.RFC822Z\n  - time.RFC850\n  - time.RFC1123\n  - time.RFC1123Z\n  - time.RFC3339\n\nTimestamp also support a convenient value `now` which will set the value from `time.Now()` at `Default()` method call time.\n\n```proto\ngoogle.protobuf.Timestamp timestamp = 19 [(defaults.value).timestamp = \"now\"];\ngoogle.protobuf.Timestamp time_value_field_with_default = 18 [(defaults.value).timestamp = \"1952-03-11T00:00:00Z\"];\n```\n\n### Enums\n\nThe enum index value if currently to zero.\n\n```proto\nenum Enum {\n    NONE = 0;\n    ONE = 1;\n    TWO = 2;\n}\nEnum enum = 16 [(defaults.value).enum = 1];\n```\n\n### oneof\n\nIf the `defaults.oneof` option is set, the `oneof` will be initialized with a struct of the *oneof type wrapper*, \nthe regular field type `default` option will be applied.\n\n```proto\noneof one_of {\n    option (defaults.oneof) = \"two\";\n    OneOfOne one = 29 [(defaults.value).message = {defaults: true, initialize: true}];\n    OneOfTwo two = 30 [(defaults.value).message = {defaults: true, initialize: true}];\n    OneOfThree three = 31 [(defaults.value).message = {defaults: true, initialize: true}];\n    Enum four = 32 [(defaults.value).enum = 1];\n}\n```\n\n\n### Repeated and Maps\n\n`repeated` and `maps` are not supported.\n\n\n## All types example\n```proto\nsyntax = \"proto3\";\n\npackage tests;\n\noption go_package = \"go.linka.cloud/protoc-gen-defaults/tests/pb;pb\";\n\nimport \"defaults/defaults.proto\";\n\nimport \"google/protobuf/wrappers.proto\";\nimport \"google/protobuf/timestamp.proto\";\nimport \"google/protobuf/duration.proto\";\n\nmessage Types {\n    // Scalar Field Types\n    float float = 1 [(defaults.value).float = 0.42];\n    double double = 2 [(defaults.value).double = 0.42];\n    int32 int32 = 3 [(defaults.value).int32 = 42];\n    int64 int64 = 4 [(defaults.value).int64 = 42];\n    uint32 uint32 = 5 [(defaults.value).uint32 = 42];\n    uint64 uint64 = 6 [(defaults.value).uint64 = 42];\n    sint32 sint32 = 7 [(defaults.value).sint32 = 42];\n    sint64 sint64 = 8 [(defaults.value).sint64 = 42];\n    fixed32 fixed32 = 9 [(defaults.value).fixed32 = 42];\n    fixed64 fixed64 = 10 [(defaults.value).fixed64 = 42];\n    sfixed32 sfixed32 = 11 [(defaults.value).sfixed32 = 42];\n    sfixed64 sfixed64 = 12 [(defaults.value).sfixed64 = 42];\n    bool bool = 13 [(defaults.value).bool = true];\n    string string = 14 [(defaults.value).string = \"42\"];\n    bytes bytes = 15 [(defaults.value).bytes = \"42\"];\n\n    // Complex Field Types\n    enum Enum {\n        NONE = 0;\n        ONE = 1;\n        TWO = 2;\n    }\n    Enum enum = 16 [(defaults.value).enum = 1];\n    Message message = 17 [(defaults.value).message = {initialize: true, defaults: false}];\n    oneof one_of {\n        option (defaults.oneof) = \"two\";\n        OneOfOne one = 29 [(defaults.value).message = {defaults: true, initialize: true}];\n        OneOfTwo two = 30 [(defaults.value).message = {defaults: true, initialize: true}];\n        OneOfThree three = 31 [(defaults.value).message = {defaults: true, initialize: true}];\n        Enum four = 32 [(defaults.value).enum = 1];\n    }\n    \n    // WellKnow types\n    google.protobuf.Duration duration = 18 [(defaults.value).duration = \"2d\"];\n    google.protobuf.Timestamp timestamp = 19 [(defaults.value).timestamp = \"now\"];\n    google.protobuf.DoubleValue double_value = 20 [(defaults.value).double = 0.42];\n    google.protobuf.FloatValue float_value = 21 [(defaults.value).float = 0.42];\n    google.protobuf.Int64Value int64_value = 22 [(defaults.value).int64 = 42];\n    google.protobuf.UInt64Value uint64_value = 23 [(defaults.value).uint64 = 42];\n    google.protobuf.Int32Value int32_value = 24 [(defaults.value).int32 = 42];\n    google.protobuf.UInt32Value uint32_value = 25 [(defaults.value).uint32 = 42];\n    google.protobuf.BoolValue bool_value = 26 [(defaults.value).bool = false];\n    google.protobuf.StringValue string_value = 27 [(defaults.value).string = \"42\"];\n    google.protobuf.BytesValue bytes_value = 28 [(defaults.value).bytes = \"42\"];\n}\n\nmessage Message {\n    string field = 1 [(defaults.value).string = \"lonely field\"];\n}\n\nmessage OneOfOne {\n    option (defaults.ignored) = true;\n    string string_field = 1 [(defaults.value).string = \"string_field\"];\n}\n\nmessage OneOfTwo {\n    string string_field = 1 [(defaults.value).string = \"string_field\"];\n}\n\nmessage OneOfThree {\n    option (defaults.disabled) = true;\n    string string_field = 1 [(defaults.value).string = \"string_field\"];\n}\n\n```\n\n### Using reflection / without code generation\n\nSetting protobuf message defaults is also supported using reflection:\n\n```go\npackage main\n\nimport (\n\tpb \"...\"\n\t\"go.linka.cloud/protoc-gen-defaults/defaults\"\n)\n\nfunc main() {\n\tvar msg pb.MyMessage\n\tdefaults.Apply(\u0026msg)\n}\n\n```\n\n## TODO\n- [x] docs\n- [x] oneof support\n- [x] set default values by using [Protobuf reflection](https://pkg.go.dev/google.golang.org/protobuf@v1.27.1/reflect/protoreflect)\n- [ ] add more generic methods to use as default value, e.g. *uuid*, *bsonid*... ?\n- [ ] repeated support ?\n- [ ] maps support ?\n- [x] bytes support\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinka-cloud%2Fprotoc-gen-defaults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinka-cloud%2Fprotoc-gen-defaults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinka-cloud%2Fprotoc-gen-defaults/lists"}