{"id":17746646,"url":"https://github.com/trivigy/ref","last_synced_at":"2025-10-12T00:04:55.815Z","repository":{"id":57551427,"uuid":"172552134","full_name":"trivigy/ref","owner":"trivigy","description":"Implements functions for de-referencing primitive types","archived":false,"fork":false,"pushed_at":"2019-07-08T00:37:38.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-12T00:03:11.383Z","etag":null,"topics":["golang","optional","pointers","struct"],"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/trivigy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-25T17:28:20.000Z","updated_at":"2020-04-18T04:26:54.000Z","dependencies_parsed_at":"2022-09-26T18:41:28.575Z","dependency_job_id":null,"html_url":"https://github.com/trivigy/ref","commit_stats":null,"previous_names":["syncaide/ref"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/trivigy/ref","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivigy%2Fref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivigy%2Fref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivigy%2Fref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivigy%2Fref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trivigy","download_url":"https://codeload.github.com/trivigy/ref/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trivigy%2Fref/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009470,"owners_count":26084609,"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-10-11T02:00:06.511Z","response_time":55,"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":["golang","optional","pointers","struct"],"created_at":"2024-10-26T08:08:09.403Z","updated_at":"2025-10-12T00:04:55.781Z","avatar_url":"https://github.com/trivigy.png","language":"Go","readme":"# Ref\n\n[![CircleCI branch](https://img.shields.io/circleci/project/github/trivigy/ref/master.svg?label=master\u0026logo=circleci)](https://circleci.com/gh/trivigy/workflows/ref)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.md)\n[![](https://godoc.org/github.com/trivigy/ref?status.svg\u0026style=flat)](http://godoc.org/github.com/trivigy/ref)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/trivigy/ref.svg?style=flat\u0026color=e36397\u0026label=release)](https://github.com/trivigy/ref/releases/latest)\n\n## Introduction\nIn golang v1, unfortunately, there is no nice builtin way to represent optional \n`struct` fields for primitives whose zero value is individualized for each \nprimitive. A lot of debating has been done and people hold different opinions \nas to what is the best solution. This library is my personal preferred way\nof dealing with the situation.\n\n## Example\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\n\t\"github.com/trivigy/ref\"\n)\n\ntype Sample struct {\n\tField *string `json:\"field,omitempty\"`\n}\n\nfunc main() {\n\tresult := Sample{\n\t\tField: ref.String(\"example\"),\n\t}\n\t\n\tif result.Field != nil {\n\t\tfmt.Print(\"'Field' is set\")\n\t}\n}\n```\n\n## Alternatives\n* https://www.reddit.com/r/golang/comments/1tst88/optional_field_in_a_struct_pointer_vs_nullintlike/\n\nIf you hold another opinion feel free to share it either via discord or on \ngolang github channels. Or better yet share a PR with a new link added above.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrivigy%2Fref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrivigy%2Fref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrivigy%2Fref/lists"}