{"id":16686330,"url":"https://github.com/yoheimuta/go-rewrite","last_synced_at":"2026-05-18T22:34:28.515Z","repository":{"id":84659093,"uuid":"140988072","full_name":"yoheimuta/go-rewrite","owner":"yoheimuta","description":"go-rewrite is a thin go package which helps replacing files.","archived":false,"fork":false,"pushed_at":"2018-07-16T00:37:22.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-20T10:47:55.892Z","etag":null,"topics":["go","golang","grep","library","rewrite","sed"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yoheimuta.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":"2018-07-15T00:50:57.000Z","updated_at":"2018-11-03T14:24:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"ada93e2e-b263-40af-994f-268925efdb3c","html_url":"https://github.com/yoheimuta/go-rewrite","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2Fgo-rewrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2Fgo-rewrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2Fgo-rewrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoheimuta%2Fgo-rewrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoheimuta","download_url":"https://codeload.github.com/yoheimuta/go-rewrite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243428436,"owners_count":20289317,"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":["go","golang","grep","library","rewrite","sed"],"created_at":"2024-10-12T15:05:27.079Z","updated_at":"2025-12-29T22:49:51.482Z","avatar_url":"https://github.com/yoheimuta.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-rewrite [![GoDoc](https://godoc.org/github.com/yoheimuta/go-rewrite/rewrite?status.svg)](https://godoc.org/github.com/yoheimuta/go-rewrite/rewrite) [![Build Status](https://travis-ci.org/yoheimuta/go-rewrite.svg?branch=master)](https://travis-ci.org/yoheimuta/go-rewrite)\n\ngo-rewrite is a thin go package which helps replacing files.\n\nYou can use this package...\n\n- To focus on coding to filter files and overwrite the file with a new content.\n- To search for files under intricate conditions instead of grep.\n- To overwrite the files under intricate conditions instead of sed.\n- To traverse a directory much faster with utilizing goroutines.\n\n### Motivation\n\nFor example, if you want to replace comments on multiple lines of `func or class or var declaration`\nfrom `//` to `///` for files with extension .swift.\n\nIt is easier to write Go's code than to do it with grep and sed.\n\n### Installation\n\n```\ngo get github.com/yoheimuta/go-rewrite\n```\n\n### Usage\n\nSee `_example/simple` and `_example/intricate` in detail.\n\n```go\nfunc main() {\n\trule := \u0026myrule{}\n\trewrite.Run(\".\", rule)\n}\n\ntype myrule struct{}\n\n// Filter filters the file using the filepath.\nfunc (*myrule) Filter(filepath string) (bool, error) {\n\tif !strings.HasSuffix(filepath, \".txt\") {\n\t\treturn false, nil\n\t}\n\treturn true, nil\n}\n\n// Mapping maps the file content with new one.\nfunc (*myrule) Mapping(content []byte) ([]byte, bool, error) {\n\tcontent = bytes.Replace(content, []byte(\"hoge\"), []byte(\"fuga\"), -1)\n\treturn content, true, nil\n}\n\n// Output writes the content to the file.\nfunc (*myrule) Output(_ string, content []byte) error {\n\treturn ioutil.WriteFile(filepath, content, 0644)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoheimuta%2Fgo-rewrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoheimuta%2Fgo-rewrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoheimuta%2Fgo-rewrite/lists"}