{"id":43223293,"url":"https://github.com/gnames/gnlib","last_synced_at":"2026-02-01T09:15:59.292Z","repository":{"id":57549784,"uuid":"307078852","full_name":"gnames/gnlib","owner":"gnames","description":"Miscellaneous shared libraries for GNA projects","archived":false,"fork":false,"pushed_at":"2026-01-25T13:02:06.000Z","size":194,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-01-26T04:54:25.996Z","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":"2020-10-25T10:58:14.000Z","updated_at":"2026-01-25T13:01:57.000Z","dependencies_parsed_at":"2026-01-25T15:03:53.210Z","dependency_job_id":null,"html_url":"https://github.com/gnames/gnlib","commit_stats":null,"previous_names":[],"tags_count":118,"template":false,"template_full_name":null,"purl":"pkg:github/gnames/gnlib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gnames","download_url":"https://codeload.github.com/gnames/gnlib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnames%2Fgnlib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28974540,"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:58.083Z","updated_at":"2026-02-01T09:15:59.287Z","avatar_url":"https://github.com/gnames.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gnlib\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/gnames/gnlib.svg)](https://pkg.go.dev/github.com/gnames/gnlib)\n\nA collection of shared utilities and entities for Global Names Architecture Go projects.\n\n## Features\n\n- **User-Friendly Error Handling**: Terminal-colorized error messages with clean output\n- **Generic Utilities**: Type-safe Map, Filter, and other collection operations\n- **Channel Operations**: Chunk channel data into manageable batches\n- **Version Comparison**: Semantic version comparison utilities\n- **UTF-8 Handling**: Fix and normalize UTF-8 strings\n- **Domain Entities**: Shared types for taxonomic name verification, reconciliation, and matching\n\n## Installation\n\n```bash\ngo get github.com/gnames/gnlib\n```\n\n## Usage\n\n### User-Friendly Error Messages\n\nThe error handling system allows you to create errors that produce clean, colorized output for the terminal, while preserving the underlying error details for logging.\n\n#### Static FormatMessage Function\n\nUse `FormatMessage` as a standalone function for any message formatting needs:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/gnames/gnlib\"\n)\n\nfunc main() {\n\t// Format a message with tags and variables\n\tmsg := gnlib.FormatMessage(\n\t\t\"Processing \u003ctitle\u003e%s\u003c/title\u003e: \u003cem\u003e%d\u003c/em\u003e items found\",\n\t\t[]any{\"data.csv\", 42},\n\t)\n\tfmt.Println(msg)\n\t// Output (with colors): Processing data.csv: 42 items found\n}\n```\n\n#### MessageBase for Structured Errors\n\nCreate custom error types that embed `MessageBase` for more structured error handling:\n\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/gnames/gnlib\"\n)\n\nfunc main() {\n\t// Create a custom error type\n\ttype FileError struct {\n\t\terror\n\t\tgnlib.MessageBase\n\t}\n\n\t// Create a new error with a format string and variables\n\tbase := gnlib.NewMessage(\n\t\t\"\u003cwarning\u003eCould not process file '%s'\u003c/warning\u003e\",\n\t\t[]any{\"important.txt\"},\n\t)\n\terr := FileError{\n\t\terror:       errors.New(\"file processing failed\"),\n\t\tMessageBase: base,\n\t}\n\n\t// The UserMessage() method returns the formatted, colorized string\n\tfmt.Fprintln(os.Stdout, err.UserMessage())\n\n\t// Example of wrapping the error\n\twrappedErr := fmt.Errorf(\"operation failed: %w\", err)\n\n\t// You can inspect the error chain to get the user-friendly message\n\tvar gnErr gnlib.Error\n\tif errors.As(wrappedErr, \u0026gnErr) {\n\t\tfmt.Fprintln(os.Stdout, \"---\")\n\t\tfmt.Fprintln(os.Stdout, \"Message from wrapped error:\")\n\t\tfmt.Fprintln(os.Stdout, gnErr.UserMessage())\n\t}\n}\n```\n\nThis will produce the following output (with colors in the terminal):\n\n```\nCould not process file 'important.txt'\n---\nMessage from wrapped error:\nCould not process file 'important.txt'\n```\n\n#### Colorization Tags\n\nBoth `FormatMessage` and `UserMessage()` recognize the following tags for styling terminal output:\n\n-   `\u003ctitle\u003e...\u003c/title\u003e`: Renders text in **green**.\n-   `\u003cwarning\u003e...\u003c/warning\u003e`: Renders text in **red**.\n-   `\u003cem\u003e...\u003c/em\u003e`: Renders text in **yellow**.\n\n### Generic Utilities\n\nThe library provides type-safe generic functions for common operations:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/gnames/gnlib\"\n)\n\nfunc main() {\n    // Map transforms a slice\n    numbers := []int{1, 2, 3, 4, 5}\n    doubled := gnlib.Map(numbers, func(n int) int { return n * 2 })\n    fmt.Println(doubled) // [2 4 6 8 10]\n\n    // Filter returns elements matching a condition\n    evens := gnlib.FilterFunc(numbers, func(n int) bool { return n%2 == 0 })\n    fmt.Println(evens) // [2 4]\n\n    // SliceMap creates a lookup map from a slice\n    fruits := []string{\"apple\", \"banana\", \"cherry\"}\n    fruitMap := gnlib.SliceMap(fruits)\n    fmt.Println(fruitMap[\"banana\"]) // 1\n}\n```\n\n### Channel Operations\n\nProcess channel data in chunks:\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"github.com/gnames/gnlib\"\n)\n\nfunc main() {\n    input := make(chan int)\n    go func() {\n        for i := 1; i \u003c= 10; i++ {\n            input \u003c- i\n        }\n        close(input)\n    }()\n\n    chunked := gnlib.ChunkChannel(context.Background(), input, 3)\n    for chunk := range chunked {\n        fmt.Println(chunk)\n    }\n    // Output:\n    // [1 2 3]\n    // [4 5 6]\n    // [7 8 9]\n    // [10]\n}\n```\n\n### Version Comparison\n\nCompare semantic versions:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/gnames/gnlib\"\n)\n\nfunc main() {\n    result := gnlib.CmpVersion(\"v1.2.3\", \"v1.2.4\")\n    fmt.Println(result) // -1 (first is less than second)\n\n    result = gnlib.CmpVersion(\"v2.0.0\", \"v1.9.9\")\n    fmt.Println(result) // 1 (first is greater than second)\n\n    result = gnlib.CmpVersion(\"v1.0.0\", \"v1.0.0\")\n    fmt.Println(result) // 0 (versions are equal)\n}\n```\n\n### UTF-8 String Handling\n\nFix invalid UTF-8 sequences and normalize strings:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/gnames/gnlib\"\n)\n\nfunc main() {\n    // Replaces invalid UTF-8 with U+FFFD and normalizes to NFC\n    fixed := gnlib.FixUtf8(\"invalid\\xc3\\x28utf8\")\n    fmt.Println(fixed)\n}\n```\n\n## Domain Entities\n\nThe library includes shared entity types for taxonomic name processing:\n\n- **`ent/verifier`**: Types for taxonomic name verification results\n- **`ent/reconciler`**: Types for name reconciliation and manifests\n- **`ent/matcher`**: Types for name matching operations\n- **`ent/nomcode`**: Nomenclatural code enumerations\n- **`ent/gnml`**: Global Names Markup Language types\n- **`ent/gnvers`**: Version information types\n\nSee the [API documentation](https://pkg.go.dev/github.com/gnames/gnlib) for details on these packages.\n\n## License\n\nReleased under the MIT License. See LICENSE file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnames%2Fgnlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgnames%2Fgnlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnames%2Fgnlib/lists"}