{"id":24177867,"url":"https://github.com/heat1q/opt","last_synced_at":"2025-08-14T05:12:37.164Z","repository":{"id":57692991,"uuid":"483670473","full_name":"heat1q/opt","owner":"heat1q","description":"Option type in Go","archived":false,"fork":false,"pushed_at":"2022-04-21T17:53:51.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-20T12:24:45.839Z","etag":null,"topics":["go","golang","option","optional"],"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/heat1q.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":"2022-04-20T13:40:46.000Z","updated_at":"2022-04-21T17:21:03.000Z","dependencies_parsed_at":"2022-08-25T18:30:26.694Z","dependency_job_id":null,"html_url":"https://github.com/heat1q/opt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/heat1q/opt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heat1q%2Fopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heat1q%2Fopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heat1q%2Fopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heat1q%2Fopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heat1q","download_url":"https://codeload.github.com/heat1q/opt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heat1q%2Fopt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270364971,"owners_count":24571423,"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-14T02:00:10.309Z","response_time":75,"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":["go","golang","option","optional"],"created_at":"2025-01-13T04:16:53.547Z","updated_at":"2025-08-14T05:12:37.116Z","avatar_url":"https://github.com/heat1q.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Option\n\n[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg)](https://pkg.go.dev/github.com/heat1q/opt)\n![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/heat1q/opt)\n[![Go Report Card](https://goreportcard.com/badge/github.com/heat1q/opt)](https://goreportcard.com/report/github.com/heat1q/opt)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md)\n\nThis package implements a Rust styled `Option` type for optional values in Go. \n`Option` provides a wrapper around a value that may or may not be initialized \nand a set of methods to extract the inner value or handle nil cases.\n\n\n## Usage\n### Installation\n```\ngo get -u github.com/heat1q/opt\n```\n### Example\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/heat1q/opt\"\n)\n\nfunc main() {\n\to := opt.New(\"potato\")\n\tvalue, ok := o.Some()\n\tfmt.Println(ok) // true\n\tfmt.Println(value) // potato\n}\n```\n\n## Marshalling JSON\n`Option` solves the nullable issue for values where the \ndefault of a value is also considered valid. For instance, consider \nthe scenario where the `false` value of a `bool` is a valid instance of the nullable field.\n\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/heat1q/opt\"\n)\n\ntype data struct {\n\tFlag opt.Option[bool] `json:\"flag,omitempty\"`\n}\n\nfunc main() {\n\tvar d data\n\n\t_ = json.Unmarshal(`{}`, \u0026d)\n\t_, ok := d.Value.Some() \n\tfmt.Println(ok) // false\n\t\n\t_ = json.Unmarshal(`{\"flag\": false}`, \u0026d)\n\t_, ok = d.Value.Some() \n\tfmt.Println(ok) // true\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheat1q%2Fopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheat1q%2Fopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheat1q%2Fopt/lists"}