{"id":40955660,"url":"https://github.com/gochore/pt","last_synced_at":"2026-01-22T05:36:30.847Z","repository":{"id":43961839,"uuid":"224566080","full_name":"gochore/pt","owner":"gochore","description":"Return pointer of basic type value.","archived":false,"fork":false,"pushed_at":"2023-10-24T10:01:29.000Z","size":24,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T18:56:20.957Z","etag":null,"topics":["go","golang","pointer"],"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/gochore.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":"2019-11-28T03:54:21.000Z","updated_at":"2024-08-16T07:50:06.000Z","dependencies_parsed_at":"2024-06-19T01:28:25.811Z","dependency_job_id":null,"html_url":"https://github.com/gochore/pt","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/gochore/pt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gochore%2Fpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gochore%2Fpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gochore%2Fpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gochore%2Fpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gochore","download_url":"https://codeload.github.com/gochore/pt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gochore%2Fpt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28656378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"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","pointer"],"created_at":"2026-01-22T05:36:30.240Z","updated_at":"2026-01-22T05:36:30.841Z","avatar_url":"https://github.com/gochore.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pt\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/gochore/pt.svg)](https://pkg.go.dev/github.com/gochore/pt)\n[![Actions](https://github.com/gochore/pt/actions/workflows/test.yaml/badge.svg)](https://github.com/gochore/pt/actions)\n[![Codecov](https://codecov.io/gh/gochore/pt/branch/master/graph/badge.svg)](https://codecov.io/gh/gochore/pt)\n[![Go Report Card](https://goreportcard.com/badge/github.com/gochore/pt)](https://goreportcard.com/report/github.com/gochore/pt)\n[![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gochore/pt)](https://github.com/gochore/pt/blob/master/go.mod)\n[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/gochore/pt)](https://github.com/gochore/pt/releases)\n\nReturn pointer of basic type value.\n\n## Example\n\n```go\npackage main\n\nimport \"github.com/gochore/pt\"\n\nfunc main() {\n\t// 💀 It cannot work because Go does not allow taking the address of a constant or literal.\n\tf(\u0026100)\n\n\t// 😕 It works, but it requires two lines and declares a variable that could pollute the namespace.\n\tv := 100\n\tf(\u0026v)\n\n\t// 😊 It works. Only one line and no new variables.\n\t// But you have to use different functions for different types.\n\t// It's the only way to do it before Go1.18.\n\tf(pt.Int(100))\n\n\t// 🤩 It works. Only one line and no new variables, and a single function for all types.\n\t// It's based on generics, so it requires Go1.18 and above.\n\tf(pt.P(100))\n}\n\nfunc f(p *int) {\n\t// 💀 It could panic if p is nil.\n\tprintln(*p)\n\n\t// 😕 It's safe, but it requires multiple lines and declares a variable that could pollute the namespace.\n\tv := 0\n\tif p != nil {\n\t\tv = *p\n\t}\n\tprintln(v)\n\n\t// 🤩 It's safe. Only one line and no new variables.\n\t// It's based on generics, so it requires Go1.18 and above.\n\tprintln(pt.V(p))\n}\n```\n\n## Document\n\n### Go1.18 and later\n\n#### func P\n\n```go\nfunc P[T any](v T) *T\n```\nP returns pointer of v.\nIt's a short form of \"Pointer\" or \"GetPointer\".\n\n#### func V\n\n```go\nfunc V[T any](p *T) T\n```\nV returns value of p. If p is nil, return zero value of T.\nIt's a short form of \"Value\" or \"GetValue\".\n\n### Before Go1.18 (deprecated)\n\n#### func Bool\n\n```go\nfunc Bool(v bool) *bool\n```\nBool returns pointer of bool\n\n#### func Byte\n\n```go\nfunc Byte(v byte) *byte\n```\nByte returns pointer of byte\n\n#### func Complex128\n\n```go\nfunc Complex128(v complex128) *complex128\n```\nComplex128 returns pointer of complex128\n\n#### func Complex64\n\n```go\nfunc Complex64(v complex64) *complex64\n```\nComplex64 returns pointer of complex64\n\n#### func Duration\n\n```go\nfunc Duration(v time.Duration) *time.Duration\n```\nDuration returns pointer of time.Duration\n\n#### func Float32\n\n```go\nfunc Float32(v float32) *float32\n```\nFloat32 returns pointer of float32\n\n#### func Float64\n\n```go\nfunc Float64(v float64) *float64\n```\nFloat64 returns pointer of float64\n\n#### func Int\n\n```go\nfunc Int(v int) *int\n```\nInt returns pointer of int\n\n#### func Int16\n\n```go\nfunc Int16(v int16) *int16\n```\nInt16 returns pointer of int16\n\n#### func Int32\n\n```go\nfunc Int32(v int32) *int32\n```\nInt32 returns pointer of int32\n\n#### func Int64\n\n```go\nfunc Int64(v int64) *int64\n```\nInt64 returns pointer of int64\n\n#### func Int8\n\n```go\nfunc Int8(v int8) *int8\n```\nInt8 returns pointer of int8\n\n#### func Rune\n\n```go\nfunc Rune(v rune) *rune\n```\nRune returns pointer of rune\n\n#### func String\n\n```go\nfunc String(v string) *string\n```\nString returns pointer of string\n\n#### func Time\n\n```go\nfunc Time(v time.Time) *time.Time\n```\nTime returns pointer of time.Time\n\n#### func Uint\n\n```go\nfunc Uint(v uint) *uint\n```\nUint returns pointer of uint\n\n#### func Uint16\n\n```go\nfunc Uint16(v uint16) *uint16\n```\nUint16 returns pointer of uint16\n\n#### func Uint32\n\n```go\nfunc Uint32(v uint32) *uint32\n```\nUint32 returns pointer of uint32\n\n#### func Uint64\n\n```go\nfunc Uint64(v uint64) *uint64\n```\nUint64 returns pointer of uint64\n\n#### func Uint8\n\n```go\nfunc Uint8(v uint8) *uint8\n```\nUint8 returns pointer of uint8\n\n#### func Uintptr\n\n```go\nfunc Uintptr(v uintptr) *uintptr\n```\nUintptr returns pointer of uintptr\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgochore%2Fpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgochore%2Fpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgochore%2Fpt/lists"}