{"id":20459750,"url":"https://github.com/rosbit/reader-logger","last_synced_at":"2025-03-05T11:17:07.765Z","repository":{"id":64887695,"uuid":"578817041","full_name":"rosbit/reader-logger","owner":"rosbit","description":"a utility to output the reader content and process it simultaneously.","archived":false,"fork":false,"pushed_at":"2023-10-29T02:43:15.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T09:42:50.044Z","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/rosbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-12-16T00:21:04.000Z","updated_at":"2022-12-16T06:03:04.000Z","dependencies_parsed_at":"2025-01-15T23:53:40.937Z","dependency_job_id":"657dae02-1c86-4b09-a09e-549c288b997b","html_url":"https://github.com/rosbit/reader-logger","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Freader-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Freader-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Freader-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Freader-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosbit","download_url":"https://codeload.github.com/rosbit/reader-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242014722,"owners_count":20057880,"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":[],"created_at":"2024-11-15T12:17:10.146Z","updated_at":"2025-03-05T11:17:07.727Z","avatar_url":"https://github.com/rosbit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reader-logger, a utility to output the reader content and process it simultaneously.\n\n## usage\n\n```go\nimport (\n\tlogr \"github.com/rosbit/reader-logger\"\n\t\"encoding/json\"\n\t\"bytes\"\n\t\"os\"\n\t\"io\"\n\t\"fmt\"\n)\n\nfunc main() {\n\t// a reader for testing\n\treader := bytes.NewBufferString(`{\"name\":\"rosbit\", \"age\": 10}`)\n\n\t// j to store the result\n\tvar j struct {\n\t\tName string `json:\"name\"`\n\t\tAge int `json:\"age\"`\n\t}\n\n\tif err := parseJSON(reader, \u0026j); err != nil {\n\t\tfmt.Printf(\"err: %v\\n\", err)\n\t\treturn\n\t}\n\tfmt.Printf(\"result: %v\\n\", j)\n}\n\n// print the content in reader and parse it.\nfunc parseJSON(reader io.Reader, j interface{}) error {\n\tr, deferFunc := logr.ReaderLogger(reader, os.Stderr, \"data in reader\") // create a new reader\n\tdefer deferFunc()\n\n\treturn json.NewDecoder(r).Decode(j) // parse JSON in the new reader\n}\n```\n\n## result\n\nrun `go test`, the result is as following:\n\n```\n--- data in reader begin ---\n{\"name\":\"rosbit\", \"age\": 10}\n--- data in reader end ---\nresult: {rosbit 10}\nPASS\nok  \tgithub.com/rosbit/reader-logger\t0.685s\n```\n\nyou can output the content of reader in any io.Writer other than os.Stderr as in the sample, of course.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Freader-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosbit%2Freader-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Freader-logger/lists"}