{"id":13694129,"url":"https://github.com/hexops/valast","last_synced_at":"2025-05-03T01:31:19.010Z","repository":{"id":46007781,"uuid":"324319290","full_name":"hexops/valast","owner":"hexops","description":"Convert Go values to their AST","archived":false,"fork":false,"pushed_at":"2025-02-19T04:57:56.000Z","size":127,"stargazers_count":310,"open_issues_count":5,"forks_count":17,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-01T04:35:58.126Z","etag":null,"topics":["ast","go","go-package","golang","reflect","repr","tostring","valast"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hexops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"slimsag"}},"created_at":"2020-12-25T08:12:43.000Z","updated_at":"2025-03-23T01:19:30.000Z","dependencies_parsed_at":"2024-11-12T20:32:59.622Z","dependency_job_id":"fa4e50ea-68c8-4c7c-b711-2534c912cb0b","html_url":"https://github.com/hexops/valast","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexops%2Fvalast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexops%2Fvalast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexops%2Fvalast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hexops%2Fvalast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hexops","download_url":"https://codeload.github.com/hexops/valast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252130396,"owners_count":21699082,"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":["ast","go","go-package","golang","reflect","repr","tostring","valast"],"created_at":"2024-08-02T17:01:25.038Z","updated_at":"2025-05-03T01:31:19.005Z","avatar_url":"https://github.com/hexops.png","language":"Go","readme":"# valast - convert Go values to their AST \u003ca href=\"https://hexops.com\"\u003e\u003cimg align=\"right\" alt=\"Hexops logo\" src=\"https://raw.githubusercontent.com/hexops/media/master/readme.svg\"\u003e\u003c/img\u003e\u003c/a\u003e\n\n\u003ca href=\"https://pkg.go.dev/github.com/hexops/valast\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/badge/github.com/hexops/valast.svg\" alt=\"Go Reference\" align=\"right\"\u003e\u003c/a\u003e\n  \n[![Go CI](https://github.com/hexops/valast/workflows/Go%20CI/badge.svg)](https://github.com/hexops/valast/actions) [![codecov](https://codecov.io/gh/hexops/valast/branch/main/graph/badge.svg?token=Iw1FdYk0m8)](https://codecov.io/gh/hexops/valast) [![Go Report Card](https://goreportcard.com/badge/github.com/hexops/valast)](https://goreportcard.com/report/github.com/hexops/valast)\n\nValast converts Go values at runtime into their `go/ast` equivalent, e.g.:\n\n```Go\nx := \u0026foo.Bar{\n    a: \"hello world!\",\n    B: 1.234,\n}\nfmt.Println(valast.String(x))\n```\n\nPrints string:\n\n```Go\n\u0026foo.Bar{a: \"hello world!\", B: 1.234}\n```\n\n## What is this useful for?\n\nThis can be useful for debugging and testing, you may think of it as a more comprehensive and configurable version of the `fmt` package's `%+v` and `%#v` formatting directives. It is similar to e.g. `repr` in Python.\n\n## Features\n\n- Produces Go code via a `go/ast`, defers formatting to the best-in-class Go formatter [gofumpt](https://github.com/mvdan/gofumpt).\n- Fully handles unexported fields, types, and values (optional.)\n- Strong emphasis on being used for producing valid Go code that can be copy \u0026 pasted directly into e.g. tests.\n- [Extensively tested](https://github.com/hexops/valast/tree/main/testdata), over 88 tests and handling numerous edge cases (such as pointers to unaddressable literal values like `\u0026\"foo\"` properly, and even [finding bugs in alternative packages'](https://github.com/shurcooL/go-goon/issues/15)).\n- Provide custom AST representations for your types with `valast.RegisterType(...)`.\n\n## Alternatives comparison\n\nThe following are alternatives to Valast, making note of the differences we found that let us to create Valast:\n\n- [github.com/davecgh/go-spew](https://github.com/davecgh/go-spew)\n    - [may be inactive](https://github.com/davecgh/go-spew/issues/128)\n    - Produces Go-like output, but not Go syntax.\n- [github.com/shurcooL/go-goon](https://github.com/shurcooL/go-goon) (based on go-spew)\n    - Produces valid Go syntax, but not via a `go/ast`.\n    - [Produces less idiomatic/terse results](https://github.com/shurcooL/go-goon/issues/11))\n    - Was deprecated in favor of valast.\n- [github.com/alecthomas/repr](https://github.com/alecthomas/repr)\n    - Produces Go syntax, but not always valid code (e.g. can emit illegal `\u002623`, whereas Valast will emit a valid expression `valast.Addr(23).(int)`), not via a `go/ast`.\n    - [Does not handle unexported fields/types/values.](https://github.com/alecthomas/repr/pull/13)\n\nYou may also wish to look at [autogold](https://github.com/hexops/autogold) and [go-cmp](https://github.com/google/go-cmp), which aim to solve the \"compare Go values in a test\" problem.\n","funding_links":["https://github.com/sponsors/slimsag"],"categories":["开源类库","Open source library","Go"],"sub_categories":["调试","Debugging"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexops%2Fvalast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhexops%2Fvalast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhexops%2Fvalast/lists"}