{"id":13616014,"url":"https://github.com/modern-go/reflect2","last_synced_at":"2025-04-14T00:31:29.585Z","repository":{"id":42559423,"uuid":"123239987","full_name":"modern-go/reflect2","owner":"modern-go","description":"reflect api without runtime reflect.Value cost","archived":false,"fork":false,"pushed_at":"2025-03-22T23:23:37.000Z","size":59,"stargazers_count":786,"open_issues_count":19,"forks_count":74,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-10T00:03:15.202Z","etag":null,"topics":["go","golang","reflect","reflection"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/modern-go.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":"2018-02-28T06:25:52.000Z","updated_at":"2025-04-04T01:18:27.000Z","dependencies_parsed_at":"2024-06-05T10:13:47.971Z","dependency_job_id":"e98e35a5-bf4c-4b1f-b8f8-f33daa780a4b","html_url":"https://github.com/modern-go/reflect2","commit_stats":{"total_commits":23,"total_committers":8,"mean_commits":2.875,"dds":"0.34782608695652173","last_synced_commit":"2b33151c9bbc5231aea69b8861c540102b087070"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-go%2Freflect2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-go%2Freflect2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-go%2Freflect2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modern-go%2Freflect2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modern-go","download_url":"https://codeload.github.com/modern-go/reflect2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647301,"owners_count":21139086,"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","reflect","reflection"],"created_at":"2024-08-01T20:01:22.298Z","updated_at":"2025-04-14T00:31:29.267Z","avatar_url":"https://github.com/modern-go.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library","Go"],"sub_categories":["开发辅助包","Development Aid Package"],"readme":"# reflect2\n\n[![Sourcegraph](https://sourcegraph.com/github.com/modern-go/reflect2/-/badge.svg)](https://sourcegraph.com/github.com/modern-go/reflect2?badge)\n[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/modern-go/reflect2)\n[![Build Status](https://travis-ci.org/modern-go/reflect2.svg?branch=master)](https://travis-ci.org/modern-go/reflect2)\n[![codecov](https://codecov.io/gh/modern-go/reflect2/branch/master/graph/badge.svg)](https://codecov.io/gh/modern-go/reflect2)\n[![rcard](https://goreportcard.com/badge/github.com/modern-go/reflect2)](https://goreportcard.com/report/github.com/modern-go/reflect2)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/modern-go/reflect2/master/LICENSE)\n\nreflect api that avoids runtime reflect.Value cost\n\n* reflect get/set interface{}, with type checking\n* reflect get/set unsafe.Pointer, without type checking\n* `reflect2.TypeByName` works like `Class.forName` found in java\n\n[json-iterator](https://github.com/json-iterator/go) use this package to save runtime dispatching cost.\nThis package is designed for low level libraries to optimize reflection performance.\nGeneral application should still use reflect standard library.\n\n# reflect2.TypeByName\n\n```go\n// given package is github.com/your/awesome-package\ntype MyStruct struct {\n\t// ...\n}\n\n// will return the type\nreflect2.TypeByName(\"awesome-package.MyStruct\")\n// however, if the type has not been used\n// it will be eliminated by compiler, so we can not get it in runtime\n```\n\n# reflect2 get/set interface{}\n\n```go\nvalType := reflect2.TypeOf(1)\ni := 1\nj := 10\nvalType.Set(\u0026i, \u0026j)\n// i will be 10\n```\n\nto get set `type`, always use its pointer `*type`\n\n# reflect2 get/set unsafe.Pointer\n\n```go\nvalType := reflect2.TypeOf(1)\ni := 1\nj := 10\nvalType.UnsafeSet(unsafe.Pointer(\u0026i), unsafe.Pointer(\u0026j))\n// i will be 10\n```\n\nto get set `type`, always use its pointer `*type`\n\n# benchmark\n\nBenchmark is not necessary for this package. It does nothing actually.\nAs it is just a thin wrapper to make go runtime public. \nBoth `reflect2` and `reflect` call same function \nprovided by `runtime` package exposed by go language.\n\n# unsafe safety\n\nInstead of casting `[]byte` to `sliceHeader` in your application using unsafe.\nWe can use reflect2 instead. This way, if `sliceHeader` changes in the future,\nonly reflect2 need to be upgraded.\n\nreflect2 tries its best to keep the implementation same as reflect (by testing).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodern-go%2Freflect2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodern-go%2Freflect2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodern-go%2Freflect2/lists"}