{"id":16003430,"url":"https://github.com/nhatthm/go-once","last_synced_at":"2025-04-05T01:40:43.997Z","repository":{"id":217094937,"uuid":"742762442","full_name":"nhatthm/go-once","owner":"nhatthm","description":"A simple library to do something exactly once","archived":false,"fork":false,"pushed_at":"2025-01-06T16:24:36.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T09:45:02.744Z","etag":null,"topics":["go","golang","once"],"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/nhatthm.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-13T09:42:24.000Z","updated_at":"2025-01-06T16:24:23.000Z","dependencies_parsed_at":"2024-12-18T06:40:51.277Z","dependency_job_id":null,"html_url":"https://github.com/nhatthm/go-once","commit_stats":null,"previous_names":["nhatthm/go-once"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-once","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-once/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-once/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-once/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhatthm","download_url":"https://codeload.github.com/nhatthm/go-once/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276096,"owners_count":20912287,"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":["go","golang","once"],"created_at":"2024-10-08T10:20:30.986Z","updated_at":"2025-04-05T01:40:43.960Z","avatar_url":"https://github.com/nhatthm.png","language":"Go","funding_links":["https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY"],"categories":[],"sub_categories":[],"readme":"# Once\n\nA simple library to do something exactly once.\n\n[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/go-once)](https://github.com/nhatthm/go-once/releases/latest)\n[![Build Status](https://github.com/nhatthm/go-once/actions/workflows/test.yaml/badge.svg)](https://github.com/nhatthm/go-once/actions/workflows/test.yaml)\n[![codecov](https://codecov.io/gh/nhatthm/go-once/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/go-once)\n[![Go Report Card](https://goreportcard.com/badge/go.nhat.io/once)](https://goreportcard.com/report/go.nhat.io/once)\n[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/go.nhat.io/once)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)\n\n## Prerequisites\n\n- `Go \u003e= 1.21`\n\n## Install\n\n```bash\ngo get go.nhat.io/once\n```\n\n## Types\n\n| Type           | Description                                                         |\n|----------------|---------------------------------------------------------------------|\n| `Once`         | An alias of [`sync.Once`](https://pkg.go.dev/sync#Once).            |\n| `Func`         | A function that can be executed exactly once.                       |\n| `Value`        | A function that returns value can be executed exactly once.         |\n| `Values`       | A function that returns values can be executed exactly once.        |\n| `FuncMap`      | A map of functions that can be executed exactly once.               |\n| `ValueMap`     | A map of functions that return value can be executed exactly once.  |\n| `ValuesMap`    | A map of functions that return values can be executed exactly once. |\n| `LazyValueMap` | A map contains values that are initialized on the first access.     |\n\n## Examples\n\n```go\npackage once_test\n\nimport (\n    \"fmt\"\n\n    \"go.nhat.io/once\"\n)\n\nfunc ExampleLazyValueMap() {\n    type Person struct {\n        ID   string\n        Name string\n    }\n\n    people := once.LazyValueMap[string, *Person]{\n        New: func(key string) *Person {\n            return \u0026Person{ID: key}\n        },\n    }\n\n    instance1 := people.Get(\"1\")\n    instance2 := people.Get(\"1\")\n\n    fmt.Println(instance2.Name)\n\n    instance1.Name = \"John Doe\"\n\n    fmt.Println(instance2.Name)\n\n    // Output:\n    //\n    // John Doe\n}\n\n```\n\n## Donation\n\nIf this project help you reduce time to develop, you can give me a cup of coffee :)\n\n### Paypal donation\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;or scan this\n\n\u003cimg src=\"https://user-images.githubusercontent.com/1154587/113494222-ad8cb200-94e6-11eb-9ef3-eb883ada222a.png\" width=\"147px\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-once","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhatthm%2Fgo-once","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-once/lists"}