{"id":43223265,"url":"https://github.com/gnames/gnfmt","last_synced_at":"2026-02-01T09:15:43.602Z","repository":{"id":57564196,"uuid":"334935091","full_name":"gnames/gnfmt","owner":"gnames","description":"format is a utility package, it contains format options, conversions to GoB, JSON, CSV","archived":false,"fork":false,"pushed_at":"2026-01-12T10:03:14.000Z","size":69,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2026-01-12T18:51:06.353Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/gnames.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-02-01T11:59:24.000Z","updated_at":"2026-01-12T10:03:18.000Z","dependencies_parsed_at":"2026-01-12T13:03:00.937Z","dependency_job_id":null,"html_url":"https://github.com/gnames/gnfmt","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/gnames/gnfmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gnames","download_url":"https://codeload.github.com/gnames/gnfmt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnfmt/sbom","scorecard":{"id":431021,"data":{"date":"2025-08-11","repo":{"name":"github.com/gnames/gnfmt","commit":"f8c86aa55b2b6f74c967c5f50837f5b465785a45"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T03:21:12.816Z","repository_id":57564196,"created_at":"2025-08-19T03:21:12.816Z","updated_at":"2025-08-19T03:21:12.816Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28974532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T08:16:14.655Z","status":"ssl_error","status_checked_at":"2026-02-01T08:06:51.373Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-02-01T09:15:42.892Z","updated_at":"2026-02-01T09:15:43.566Z","avatar_url":"https://github.com/gnames.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gnfmt\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/gnames/gnfmt)](https://goreportcard.com/report/github.com/gnames/gnfmt)\n[![GoDoc](https://godoc.org/github.com/gnames/gnfmt?status.svg)](https://godoc.org/github.com/gnames/gnfmt)\n\n`gnfmt` is a Go helper library designed to simplify data serialization and enhance command-line interface (CLI) output. It provides tools for converting Go data structures into various formats.\n\n## Features\n\n- **Data Serialization:** Convert Go objects to JSON (compact/pretty), CSV, TSV, and Gob formats\n- **Pretty Printing:** Display Go objects in a human-readable JSON format in the terminal\n- **CSV/TSV Utilities:** Read headers, convert records, and normalize row sizes\n- **Time Formatting:** Convert seconds into human-readable duration strings\n- **Flexible Encoders:** Pluggable encoder interface for easy format switching\n\n## Installation\n\n```shell\ngo get github.com/gnames/gnfmt\n```\n\n## Usage\n\n### Data Serialization and Formatting\n\n`gnfmt` supports multiple output formats for your data structures.\n\n#### Format Types\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gnames/gnfmt\"\n)\n\nfunc main() {\n\t// Create format from string\n\tformat, err := gnfmt.NewFormat(\"pretty\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(format) // Output: \"pretty JSON\"\n\n\t// Available formats:\n\t// - \"csv\"     -\u003e CSV format\n\t// - \"tsv\"     -\u003e TSV (tab-separated) format\n\t// - \"compact\" -\u003e Compact JSON (single line)\n\t// - \"pretty\"  -\u003e Pretty JSON (indented)\n}\n```\n\n#### JSON Encoding\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gnames/gnfmt\"\n)\n\ntype Person struct {\n\tName string `json:\"name\"`\n\tAge  int    `json:\"age\"`\n}\n\nfunc main() {\n\tperson := Person{Name: \"Alice\", Age: 30}\n\n\t// Compact JSON\n\tencoder := gnfmt.GNjson{Pretty: false}\n\tdata, _ := encoder.Encode(person)\n\tfmt.Println(string(data)) // {\"name\":\"Alice\",\"age\":30}\n\n\t// Pretty JSON\n\tencoder.Pretty = true\n\tdata, _ = encoder.Encode(person)\n\tfmt.Println(string(data))\n\t// {\n\t//   \"name\": \"Alice\",\n\t//   \"age\": 30\n\t// }\n\n\t// Quick pretty print\n\tfmt.Println(gnfmt.Ppr(person))\n}\n```\n\n#### Gob Encoding\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gnames/gnfmt\"\n)\n\nfunc main() {\n\tdata := map[string]int{\"apples\": 5, \"oranges\": 3}\n\n\tencoder := gnfmt.GNgob{}\n\n\t// Encode to gob\n\tgobData, err := encoder.Encode(data)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Decode from gob\n\tvar result map[string]int\n\terr = encoder.Decode(gobData, \u0026result)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(result) // map[apples:5 oranges:3]\n}\n```\n\n### CSV/TSV Utilities\n\n#### Reading CSV Headers\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gnames/gnfmt\"\n)\n\nfunc main() {\n\t// Read CSV header and get field positions\n\theader, err := gnfmt.ReadHeaderCSV(\"data.csv\", ',')\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// header is a map[string]int with field names and their indices\n\tfmt.Println(header[\"name\"])  // 0\n\tfmt.Println(header[\"email\"]) // 1\n\n\t// For TSV files, use '\\t' as separator\n\ttsvHeader, _ := gnfmt.ReadHeaderCSV(\"data.tsv\", '\\t')\n\tfmt.Println(tsvHeader)\n}\n```\n\n#### Converting Records to CSV/TSV\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gnames/gnfmt\"\n)\n\nfunc main() {\n\trecord := []string{\"John Doe\", \"john@example.com\", \"Has \\\"quotes\\\"\"}\n\n\t// Convert to CSV (comma-separated)\n\tcsvLine := gnfmt.ToCSV(record, ',')\n\tfmt.Println(csvLine)\n\t// John Doe,john@example.com,\"Has \"\"quotes\"\"\"\n\n\t// Convert to TSV (tab-separated)\n\ttsvLine := gnfmt.ToCSV(record, '\\t')\n\tfmt.Println(tsvLine)\n\t// John Doe\tjohn@example.com\t\"Has \"\"quotes\"\"\"\n}\n```\n\n#### Normalizing Row Sizes\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gnames/gnfmt\"\n)\n\nfunc main() {\n\t// Truncate or expand rows to match expected size\n\trow := []string{\"a\", \"b\", \"c\", \"d\", \"e\"}\n\n\t// Truncate to 3 fields\n\tnormalized := gnfmt.NormRowSize(row, 3)\n\tfmt.Println(normalized) // [a b c]\n\n\t// Expand to 7 fields (adds empty strings)\n\texpanded := gnfmt.NormRowSize(row, 7)\n\tfmt.Println(expanded) // [a b c d e  ]\n}\n```\n\n### Time Formatting\n\nConvert seconds into human-readable duration strings:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gnames/gnfmt\"\n)\n\nfunc main() {\n\tfmt.Println(gnfmt.TimeString(45))        // 00:00:45\n\tfmt.Println(gnfmt.TimeString(3661))      // 01:01:01\n\tfmt.Println(gnfmt.TimeString(86400))     // 1 day 00:00:00\n\tfmt.Println(gnfmt.TimeString(172800))    // 2 days 00:00:00\n\tfmt.Println(gnfmt.TimeString(90061))     // 1 day 01:01:01\n}\n```\n\n### Implementing Custom Encoders\n\nThe `Encoder` interface allows you to create custom serialization formats:\n\n```go\npackage main\n\nimport (\n\t\"github.com/gnames/gnfmt\"\n)\n\ntype MyCustomEncoder struct{}\n\nfunc (e MyCustomEncoder) Encode(input any) ([]byte, error) {\n\t// Your encoding logic here\n\treturn []byte{}, nil\n}\n\nfunc (e MyCustomEncoder) Decode(input []byte, output any) error {\n\t// Your decoding logic here\n\treturn nil\n}\n\nfunc main() {\n\tvar encoder gnfmt.Encoder = MyCustomEncoder{}\n\t// Use your custom encoder\n\t_, _ = encoder.Encode(\"data\")\n}\n```\n\n### Implementing the Outputter Interface\n\nCreate custom output formatters by implementing the `Outputter` interface:\n\n```go\npackage main\n\nimport (\n\t\"github.com/gnames/gnfmt\"\n)\n\ntype MyOutputter struct{}\n\nfunc (o MyOutputter) Output(record any, f gnfmt.Format) string {\n\t// Your custom output logic based on format\n\treturn \"\"\n}\n\nfunc main() {\n\tvar outputter gnfmt.Outputter = MyOutputter{}\n\tformat, _ := gnfmt.NewFormat(\"csv\")\n\tresult := outputter.Output(\"data\", format)\n\t_ = result\n}\n```\n\n## API Documentation\n\nFor complete API documentation, visit [GoDoc](https://godoc.org/github.com/gnames/gnfmt).\n\n## License\n\nSee the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnames%2Fgnfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgnames%2Fgnfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnames%2Fgnfmt/lists"}