{"id":13413964,"url":"https://github.com/yassinebenaid/godump","last_synced_at":"2025-04-04T15:06:28.003Z","repository":{"id":223335715,"uuid":"759467084","full_name":"yassinebenaid/godump","owner":"yassinebenaid","description":"Dump any GO variable with ease","archived":false,"fork":false,"pushed_at":"2025-03-25T09:49:15.000Z","size":907,"stargazers_count":197,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T03:52:59.030Z","etag":null,"topics":["debug","dump","formatting"],"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/yassinebenaid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-18T17:12:05.000Z","updated_at":"2025-03-30T09:01:34.000Z","dependencies_parsed_at":"2024-03-25T11:27:14.033Z","dependency_job_id":"264bf11f-228e-4260-acdb-9a71feffc2e9","html_url":"https://github.com/yassinebenaid/godump","commit_stats":{"total_commits":185,"total_committers":4,"mean_commits":46.25,"dds":"0.10270270270270265","last_synced_commit":"8147bbe3c657751a56bb75f8e621b536a63305fd"},"previous_names":["yassinebenaid/godump"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassinebenaid%2Fgodump","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassinebenaid%2Fgodump/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassinebenaid%2Fgodump/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yassinebenaid%2Fgodump/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yassinebenaid","download_url":"https://codeload.github.com/yassinebenaid/godump/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198449,"owners_count":20900079,"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":["debug","dump","formatting"],"created_at":"2024-07-30T20:01:53.918Z","updated_at":"2025-04-04T15:06:27.979Z","avatar_url":"https://github.com/yassinebenaid.png","language":"Go","funding_links":[],"categories":["Text Processing","Template Engines","文本处理"],"sub_categories":["Parsers/Encoders/Decoders","解析 器/Encoders/Decoders"],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cdiv width=\"50px\" height=\"50px\"\u003e\n\n![binoculars (3)](https://github.com/yassinebenaid/godump/assets/101285507/f2d40c7a-6f5c-4dd9-9580-3accc74efeb4)\n\n\u003c/div\u003e\n\n\u003ch1\u003e godump \u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Tests](https://github.com/yassinebenaid/godump/actions/workflows/test.yml/badge.svg)](https://github.com/yassinebenaid/godump/actions/workflows/test.yml)\n[![codecov](https://codecov.io/github/yassinebenaid/godump/graph/badge.svg?token=EAZNA85AIS)](https://codecov.io/github/yassinebenaid/godump)\n[![Go Report Card](https://goreportcard.com/badge/github.com/yassinebenaid/godump)](https://goreportcard.com/report/github.com/yassinebenaid/godump)\n[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/9241/badge)](https://www.bestpractices.dev/projects/9241)\n[![Version](https://badge.fury.io/gh/yassinebenaid%2Fgodump.svg)](https://badge.fury.io/gh/yassinebenaid%2Fgodump)\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENCE)\n[![Go Reference](https://pkg.go.dev/badge/github.com/yassinebenaid/godump.svg)](https://pkg.go.dev/github.com/yassinebenaid/godump)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/avelino/awesome-go?tab=readme-ov-file#parsersencodersdecoders)\n\n\n\u003c/div\u003e\n\nA versatile Go library designed to output any Go variable in a structured and colored format.\n\nThis library is especially useful for debugging and testing when the standard `fmt` library falls short in displaying arbitrary data effectively. It can also serve as a powerful logging adapter, providing clear and readable logs for both development and production environments.\n\n`godump` is not here to replace the `fmt` package. Instead, it provides an extension to what the `fmt.Printf(\"%#v\")` can do.\n\n## Why godump\n\n- ability to pretty print values of all types\n- well formatted output\n- unexported structs are dumped too\n- pointers are followed, and recursive pointers are taken in mind ([see examples](#example-3))\n- customizable, you have full control over the output, **you can even generate HTML if you'd like to**, [see examples](#example-4)\n- zero dependencies\n\n## Get Started\n\nInstall the library:\n\n```bash\ngo get -u github.com/yassinebenaid/godump\n```\n\nThen use the **Dump** function:\n\n```go\npackage main\n\nimport (\n\t\"github.com/yassinebenaid/godump\"\n)\n\nfunc main() {\n\tgodump.Dump(\"Anything\")\n}\n\n```\n\n## Customization\n\nIf you need more control over the output. Use the `Dumper`\n\n```go\npackage main\n\nimport (\n\t\"os\"\n\n\t\"github.com/yassinebenaid/godump\"\n)\n\nfunc main() {\n\n\tvar v = \"Foo Bar\"\n\tvar d = godump.Dumper{\n\t\tIndentation:       \"  \",\n\t\tHidePrivateFields: false,\n\t\tShowPrimitiveNamedTypes: false\n\t\tTheme: godump.Theme{\n\t\t\tString: godump.RGB{R: 138, G: 201, B: 38},\n\t\t\t// ...\n\t\t},\n\t}\n\n\td.Print(v)\n\td.Println(v)\n\td.Fprint(os.Stdout, v)\n\td.Fprintln(os.Stdout, v)\n\td.Sprint(v)\n\td.Sprintln(v)\n}\n\n```\n\n## Demo\n\n### Example 1.\n\n```go\npackage main\n\nimport (\n\t\"os\"\n\n\t\"github.com/yassinebenaid/godump\"\n)\n\nfunc main() {\n\tgodump.Dump(os.Stdout)\n}\n\n```\n\nOutput:\n\n![stdout](./demo/stdout.png)\n\n### Example 2.\n\n```go\npackage main\n\nimport (\n\t\"net\"\n\n\t\"github.com/yassinebenaid/godump\"\n)\n\nfunc main() {\n\tgodump.Dump(net.Dialer{})\n}\n\n```\n\nOutput:\n\n![dialer](./demo/dialer.png)\n\n### Example 3.\n\nThis example shows how recursive pointers are handled.\n\n```go\npackage main\n\nimport (\n\t\"github.com/yassinebenaid/godump\"\n)\n\nfunc main() {\n\ttype User struct {\n\t\tName       string\n\t\tage        int\n\t\tBestFriend *User\n\t}\n\n\tme := User{\n\t\tName: \"yassinebenaid\",\n\t\tage:  22,\n\t}\n\n    // This creates a ring\n\tme.BestFriend = \u0026me\n\n\tgodump.Dump(me)\n}\n```\n\nOutput:\n\n![pointer](./demo/pointer.png)\n\n### Example 4.\n\nThis example emphasizes how you can generate HTML\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net\"\n\t\"net/http\"\n\n\t\"github.com/yassinebenaid/godump\"\n)\n\n// Define your custom style implementation\ntype CSSColor struct {\n\tR, G, B int\n}\n\nfunc (c CSSColor) Apply(s string) string {\n\treturn fmt.Sprintf(`\u003cdiv style=\"color: rgb(%d, %d, %d); display: inline-block\"\u003e%s\u003c/div\u003e`, c.R, c.G, c.B, s)\n}\n\nfunc main() {\n\n\tvar d godump.Dumper\n\n\td.Theme = godump.Theme{\n\t\tString:        CSSColor{138, 201, 38},// edit the theme to use your implementation\n\t\tQuotes:        CSSColor{112, 214, 255},\n\t\tBool:          CSSColor{249, 87, 56},\n\t\tNumber:        CSSColor{10, 178, 242},\n\t\tTypes:         CSSColor{0, 150, 199},\n\t\tAddress:       CSSColor{205, 93, 0},\n\t\tPointerTag:    CSSColor{110, 110, 110},\n\t\tNil:           CSSColor{219, 57, 26},\n\t\tFunc:          CSSColor{160, 90, 220},\n\t\tFields:        CSSColor{189, 176, 194},\n\t\tChan:          CSSColor{195, 154, 76},\n\t\tUnsafePointer: CSSColor{89, 193, 180},\n\t\tBraces:        CSSColor{185, 86, 86},\n\t}\n\n\tvar html = `\u003cpre style=\"background: #111; padding: 10px; color: white\"\u003e`\n\thtml += d.Sprint(net.Dialer{})\n\thtml += \"\u003cpre\u003e\"\n\n    // render it to browsers\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Header().Set(\"Content-Type\", \"text/html\")\n\t\tfmt.Fprint(w, html)\n\t})\n\n\thttp.ListenAndServe(\":8000\", nil)\n\n}\n\n```\n\nOutput:\n\n![theme](./demo/theme.png)\n\nFor more examples, please take a look at [dumper_test](./dumper_test.go) along with [testdata](./testdata)\n\n## Contribution\n\nPlease read [CONTRIBUTING guidelines](.github/CONTRIBUTING.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyassinebenaid%2Fgodump","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyassinebenaid%2Fgodump","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyassinebenaid%2Fgodump/lists"}