{"id":37102181,"url":"https://github.com/sidai/defaults","last_synced_at":"2026-01-14T12:23:14.275Z","repository":{"id":57619212,"uuid":"388764498","full_name":"sidai/defaults","owner":"sidai","description":"Go default values filling for structures with support of almost all types of data","archived":false,"fork":false,"pushed_at":"2022-03-02T03:22:51.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T12:36:47.806Z","etag":null,"topics":["defaults","go","golang"],"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/sidai.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-07-23T10:30:25.000Z","updated_at":"2021-07-24T16:57:23.000Z","dependencies_parsed_at":"2022-09-14T12:41:37.917Z","dependency_job_id":null,"html_url":"https://github.com/sidai/defaults","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sidai/defaults","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidai%2Fdefaults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidai%2Fdefaults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidai%2Fdefaults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidai%2Fdefaults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sidai","download_url":"https://codeload.github.com/sidai/defaults/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidai%2Fdefaults/sbom","scorecard":{"id":822260,"data":{"date":"2025-08-11","repo":{"name":"github.com/sidai/defaults","commit":"6c269ea3dc6b71e28a4fed781c87fb6116d1aa49"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"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":"Code-Review","score":0,"reason":"Found 0/8 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":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"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":"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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sidai/defaults/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/sidai/defaults/test.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"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":"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: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE: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 'master'"],"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":10,"reason":"0 existing vulnerabilities detected","details":null,"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-23T15:53:36.725Z","repository_id":57619212,"created_at":"2025-08-23T15:53:36.725Z","updated_at":"2025-08-23T15:53:36.725Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["defaults","go","golang"],"created_at":"2026-01-14T12:23:13.544Z","updated_at":"2026-01-14T12:23:14.252Z","avatar_url":"https://github.com/sidai.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"defaults [![Test](https://github.com/sidai/defaults/actions/workflows/test.yml/badge.svg)](https://github.com/sidai/defaults/actions/workflows/test.yml) [![GitHub release](https://img.shields.io/github/release/sidai/defaults.svg)](https://github.com/sidai/defaults/releases) [![License](https://img.shields.io/github/license/sidai/defaults.svg)](./LICENSE)\n=======\nStructures default value filling with support in almost all types of data using [struct tags](http://golang.org/pkg/reflect/#StructTag) or [struct type](https://pkg.go.dev/reflect#Type)\n\nNotice\n-------\nThis repo is inspired by [go-defaults](https://github.com/sidai/go-defaults) and applies the same [LICENSE](https://github.com/sidai/defaults/blob/master/LICENSE). \n\nThe aforementioned repo provides basic default value filling for simple data types. However, \n1. It does not support complex structure like `pointer`, `interface`, `map` or `slice of map`. \n2. It always recursively fills the struct with default value but there are cases struct filling should be skipped.\n3. The default filler provided is not exported which makes it hard for customization.  \n\nI created this repo to provide more data types support, more flexibility in default value filling for struct and export the function for better customization. \n\n\nSupported Data Types\n-------\n- **Primitive Types:** \n    - `bool`\n    - `int`, `int8`, `int16`, `int32`, `int64`\n    - `uint`, `uint8`, `uint16`, `uint32`, `uint64`\n    - `float32`, `float64`\n    - `[]byte`, `string`\n    \n- **Custom Types:**\n    - `time.Duration`, `time.Time`\n    - Aliased types. e.g `type UserName string`\n    - Self-defined types. e.g. `type User struct {Name string, Age int}`\n    \n- **Complex Types:**\n    - `map`, `slice`, `interface`, `struct`\n    \n- **Nested Types:**\n    - e.g. `map[int][]*User`, `[]map[int]*User`, `map[int]map[int]*User` \n    \n- **Pointer Types:**\n    - e.g. `*int`, `*User`, `**int`, `**User` \n   \nRules\n-------\n- Filling rules can be defined either by [Kind](https://pkg.go.dev/reflect#Kind) or [Type](https://pkg.go.dev/reflect#Type) \u003cbr\u003e\n  If both rules found when filling a field, \n  [FuncsByKind](https://github.com/sidai/defaults/blob/master/filler.go#L17) is used first before\n  [FuncsByType](https://github.com/sidai/defaults/blob/master/filler.go#L18) \n\n- Skip default filling for non-zero fields to prevent fields with initial value being reset\n\n- By default struct is recursively filled only when it is *empty* \u003cbr\u003e \n  Use `default:\"omit\"` to always skip struct filling \u003cbr\u003e\n  Use `default:\"dive\"` to always apply struct filling even when it is not empty\n\nUsage\n-------\n- **Installation**: ```go get github.com/sidai/defaults```\n\n- **[FuncsByKind](https://github.com/sidai/defaults/blob/master/filler.go#L17) Examples**:\n    ```go\n    type Role string\n    \n    type Admin struct {\n        Name string\n        Role Role   `default:\"admin\"`\n    }\n    \n    func (a *Admin) GetRole() Role {\n        return a.Role\n    }\n    \n    type User interface {\n        GetRole() Role\n    }\n    \n    type ExampleFuncsByKind struct {\n        Int              int           `default:\"1\"`                         // Primitive\n        IntPtrPtr        **int         `default:\"1\"`                         // Ptr type\n        Role             Role          `default:\"DBA\"`                       // Alias of Primitive\n        Duration         time.Duration `default:\"1s\"`                        // Duration\n        Time             time.Time     `default:\"2007-07-07T07:07:07.007Z\"`  // Time\n        ListOfInt        []int         `default:\"[1,2,3,4]\"`                 // Slice\n        ListOfIntList    [][]int       `default:\"[[1,2],[3,4]]\"`             // 2D Slice\n        ListOfIntMap     []map[int]int `default:\"[{1:10,2:20},{3:30,4:40}]\"` // Slice of Map\n    \n        Admin            Admin                                               // Struct \n        AdminPtr         *Admin                                              // Struct Ptr\n        AdminOmit        Admin         `default:\"omit\"`                      // Struct w Omit\n        AdminWithVal     Admin                                               // Struct w Initial Value\n        AdminWithValDive Admin         `default:\"dive\"`                      // Struct w Dive\n        User             User                                                // Interface\n        UserWithVal      User                                                // Interface w Implementation\n        UserWithValDive  User          `default:\"dive\"`                      // Interface w Implementation \u0026 Dive\n    }\n    \n    ...\n    \n    foo := ExampleFuncsByKind{\n   \t\tAdminWithVal:     Admin{Name: \"admin1\"},\n   \t\tAdminWithValDive: Admin{Name: \"admin2\"},\n   \t\tUserWithVal:      \u0026Admin{Name: \"admin3\"},\n   \t\tUserWithValDive:  \u0026Admin{Name: \"admin4\"}, \n    }\n  \n    SetDefaults(\u0026foo)\n    \n    foo = {\n        \"Int\": 1,\n        \"IntPtrPtr\": (**int) 1,\n        \"Role\": \"DBA\",\n        \"Duration\": 1s,\n        \"Time\": \"2007-07-07 07:07:07.007 +0000 UTC\",\n        \"ListOfInt\": [1, 2, 3, 4],\n        \"ListOfIntList\": [[1, 2], [3, 4]],\n        \"ListOfIntMap\": [{1: 10, 2: 20}, {3: 30, 4: 40}],\n        \"Admin\": {\"Name\": \"\", \"Role\": \"admin\"},                         // Role filled with default value \"admin\" for emtpy field\n        \"AdminPtr\": (*Admin) {\"Name\": \"\", \"Role\": \"admin\"},             // Role filled with default value \"admin\" for emtpy pointer field\n        \"AdminOmit\": {\"Name\": \"\", \"Role\": \"\"},                          // Role not filled even when AdminOmit is emtpy since \"omit\" tag found\n        \"AdminWithVal\": {\"Name\": \"admin1\", \"Role\": \"\"},                 // Role not filled since AdminWithVal field is not empty\n        \"AdminWithValDive\": {\"Name\": \"admin2\", \"Role\": \"admin\"},        // Role filled even when AdminWithValDive field is not empty since \"dive\" tag found\n        \"User\": nil,                                                    // User not filled no implementation found\n        \"UserWithVal\": (*Admin) {\"Name\": \"admin3\", \"Role\": \"\"},         // User Role not filled since implementation UserWithVal is not empty \n        \"UserWithValDive\": (*Admin) {\"Name\": \"admin4\", \"Role\": \"admin\"} // User Role filled since implementation UserWithValDive has \"dive\" tag\n    }\n    ```\n  \n- **[FuncsByType](https://github.com/sidai/defaults/blob/master/filler.go#L18)  Examples**:\n    ```go\n    type Enum string\n    \n    type DefaultData struct {\n    \tString string\n    \tInt    int\n    }\n    \n    type ExampleFuncsByType struct {\n    \tEnum                   Enum\n    \tEnumWithTag            Enum        `default:\"tag\"`\n    \tEnumWithValueNTag      Enum        `default:\"tag\"`\n    \tDefaultData            DefaultData\n    \tDefaultDataOmit        DefaultData `default:\"omit\"`\n    \tDefaultDataWithVal     DefaultData\n    \tDefaultDataWithValDive DefaultData `default:\"dive\"`\n    }\n    \n    foo := ExampleFuncsByType{\n        EnumWithValueNTag:      Enum(\"value\"),\n        DefaultDataWithVal:     DefaultData{Int: 1},\n        DefaultDataWithValDive: DefaultData{Int: 1},\n    }\n\n    RegisterDefaultType(Enum(\"type\"))\n    RegisterDefaultType(DefaultData{String: \"type\", Int: 7})\n    SetDefaults(\u0026foo)\n  \n    ...\n  \n    foo = {\n        \"Enum\": \"type\",                                // Use FuncsByType\n        \"EnumWithTag\": \"tag\",                          // Use tag as FuncsByKind has higher precedence\n        \"EnumWithValueNTag\": \"value\",                  // No filling applied as value is not empty\n        \"DefaultData\": {String: \"type\", Int: 7},       // Use FuncsByType\n        \"DefaultDataOmit\": {String: \"\", Int: 0},       // Omit tag works for FuncsByType\n        \"DefaultDataWithVal\": {String: \"\", Int: 1},    // FuncsByType skip filling when value is not empty\n        \"DefaultDataWithValDive\": {String: \"\", Int: 1} // FuncsByType ignores dive tag as it works on the extra type only\n    }\n    ```\n    \n- More Examples [*Here*](https://github.com/sidai/defaults/blob/master/filler_test.go)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidai%2Fdefaults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidai%2Fdefaults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidai%2Fdefaults/lists"}