{"id":19666574,"url":"https://github.com/xaionaro-go/unsafetools","last_synced_at":"2026-01-26T02:02:13.367Z","repository":{"id":57492636,"uuid":"206399345","full_name":"xaionaro-go/unsafetools","owner":"xaionaro-go","description":"Access to private/unexported fields of a structure","archived":false,"fork":false,"pushed_at":"2024-10-24T01:43:11.000Z","size":16,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-17T14:42:05.068Z","etag":null,"topics":["access","golang","modify","private","reflect","struct","unexported","unsafe"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xaionaro-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":"2019-09-04T19:40:41.000Z","updated_at":"2024-10-24T01:43:15.000Z","dependencies_parsed_at":"2024-11-11T16:43:09.185Z","dependency_job_id":null,"html_url":"https://github.com/xaionaro-go/unsafetools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xaionaro-go/unsafetools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Funsafetools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Funsafetools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Funsafetools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Funsafetools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xaionaro-go","download_url":"https://codeload.github.com/xaionaro-go/unsafetools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Funsafetools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28764416,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"online","status_checked_at":"2026-01-26T02:00:08.215Z","response_time":59,"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":["access","golang","modify","private","reflect","struct","unexported","unsafe"],"created_at":"2024-11-11T16:28:08.912Z","updated_at":"2026-01-26T02:02:13.345Z","avatar_url":"https://github.com/xaionaro-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Coverage Status](https://coveralls.io/repos/github/xaionaro-go/unsafetools/badge.svg?branch=master)](https://coveralls.io/github/xaionaro-go/unsafetools?branch=master)\n[![GoDoc](https://godoc.org/github.com/xaionaro-go/unsafetools?status.svg)](https://godoc.org/github.com/xaionaro-go/unsafetools)\n[![Go Report Card](https://goreportcard.com/badge/github.com/xaionaro-go/unsafetools)](https://goreportcard.com/report/github.com/xaionaro-go/unsafetools)\n\n# Description\n\nThis package provides function `FieldByName` to access to any field (including private/unexported) of a structure.\n\n# Use case\n\nThis package is supposed to be used for unit-tests only. If you think about using it in a real production then it seems it is something wrong in your program. However yes, you can use is if you want :)\n\n[An use case example in github.com/xaionaro-go/picapi](https://github.com/xaionaro-go/picapi/blob/2ac776187b13158bca34bafe7cbff5487f478b9b/httpserver/http_server_handle_resize_test.go#L22).\n\n# Example\n\n`github.com/xaionaro-go/unsafetools/test/types.go`\n```go\npackage test\n\ntype privateStruct struct {\n\tenableBonus bool\n}\n\ntype StructWithPrivate struct {\n\tprivateStruct\n\n\tinitialized bool\n}\n\nfunc (s *StructWithPrivate) HelloWorld() (result string) {\n\tdefer func() {\n\t\tif s.enableBonus {\n\t\t\tresult += ` (bonus!)`\n\t\t}\n\t}()\n\n\tif !s.initialized {\n\t\treturn ``\n\t}\n\n\treturn `hello world!`\n}\n```\n\n`github.com/xaionaro-go/unsafetools/unsafetools_test.go`\n```go\nimport (\n\t\"testing\"\n\n\t\"github.com/stretchr/testify/assert\"\n\n\t\"github.com/xaionaro-go/unsafetools/test\"\n)\n\nfunc TestFindByName_positive(t *testing.T) {\n\ts := \u0026test.StructWithPrivate{}\n\n\tassert.Equal(t, ``, s.HelloWorld())\n\n\t*FieldByName(s, `initialized`).(*bool) = true\n\tassert.Equal(t, `hello world!`, s.HelloWorld())\n\n\t*FieldByName(s, `initialized`).(*bool) = false\n\tassert.Equal(t, ``, s.HelloWorld())\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaionaro-go%2Funsafetools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxaionaro-go%2Funsafetools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaionaro-go%2Funsafetools/lists"}