{"id":16912497,"url":"https://github.com/boyter/gocodewalker","last_synced_at":"2025-04-07T11:07:36.597Z","repository":{"id":57545142,"uuid":"298130771","full_name":"boyter/gocodewalker","owner":"boyter","description":"Library to help with walking of code directories in go","archived":false,"fork":false,"pushed_at":"2025-03-12T23:47:24.000Z","size":126,"stargazers_count":76,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T09:08:57.739Z","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/boyter.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}},"created_at":"2020-09-24T00:49:50.000Z","updated_at":"2025-03-31T08:11:43.000Z","dependencies_parsed_at":"2024-05-29T07:42:03.303Z","dependency_job_id":"9030dd5a-5576-4252-9d5f-e26f605bd647","html_url":"https://github.com/boyter/gocodewalker","commit_stats":null,"previous_names":["boyter/go-code-walker"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boyter%2Fgocodewalker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boyter%2Fgocodewalker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boyter%2Fgocodewalker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boyter%2Fgocodewalker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boyter","download_url":"https://codeload.github.com/boyter/gocodewalker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640462,"owners_count":20971557,"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-10-13T19:10:17.445Z","updated_at":"2025-04-07T11:07:36.577Z","avatar_url":"https://github.com/boyter.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gocodewalker\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/boyter/gocodewalker)](https://goreportcard.com/report/github.com/boyter/gocodewalker)\n[![Str Count Badge](https://sloc.xyz/github/boyter/gocodewalker/)](https://github.com/boyter/gocodewalker/)\n\nLibrary to help with walking of code directories in Go. \n\nThe problem. You want to walk the directories of a code repository. You want to respect .gitignore and .ignore files, and \nsome are nested. This library is the answer.\n\n - Designed to walk code repositories or find the root of them.\n - By default, respects both .gitignore and .ignore files (can be disabled) and nested ones for accuracy\n - Has configurable options for skipping files based on regex, extension or general match\n - Uses readdir to provide as fast as possible file walking\n\nNB this was moved from go-code-walker due to the name being annoying and to ensure it has a unique package name. Should still be drop in replaceable\nso long as you refer to the new package name.\n\nhttps://pkg.go.dev/github.com/boyter/gocodewalker\n\nPackage provides file operations specific to code repositories such as walking the file tree obeying .ignore and .gitignore files\nor looking for the root directory assuming already in a git project.\n\nExample of usage,\n\n```go\nfileListQueue := make(chan *gocodewalker.File, 100)\n\nfileWalker := gocodewalker.NewFileWalker(\".\", fileListQueue)\n\n// restrict to only process files that have the .go extension\nfileWalker.AllowListExtensions = append(fileWalker.AllowListExtensions, \"go\")\n\n// handle the errors by printing them out and then ignore\nerrorHandler := func(e error) bool {\n    fmt.Println(\"ERR\", e.Error())\n    return true\n}\nfileWalker.SetErrorHandler(errorHandler)\n\ngo fileWalker.Start()\n\nfor f := range fileListQueue {\n    fmt.Println(f.Location)\n}\n```\n\nThe above by default will recursively add files to the fileListQueue respecting both .ignore and .gitignore files if found, and\nonly adding files with the go extension into the queue.\n\nYou can also run the walker in parallel with the results intermixed if required,\n\n```go\nfileListQueue := make(chan *gocodewalker.File, 100)\n\nfileWalker := gocodewalker.NewParallelFileWalker([]string{\".\", \"someotherdir\"}, fileListQueue)\ngo fileWalker.Start()\n\nfor f := range fileListQueue {\n    fmt.Println(f.Location)\n}\n```\n\nAll code is licenced as MIT.\n\n### Error Handler\n\nYou can supply your own error handler when walking. This allows you to perform an action when there is an error\nand decide if the walker should continue to process, or return.\n\nThe simplest handler is the below, which if set will swallow all errors and continue as best it can.\n\n```go\nerrorHandler := func(e error) bool {\n    return true\n}\nfileWalker.SetErrorHandler(errorHandler)\n```\n\nIf you wanted to return on errors you could use the following.\n\n```go\nerrorHandler := func(e error) bool {\n    return false\n}\nfileWalker.SetErrorHandler(errorHandler)\n```\n\nIf you wanted to terminate walking on an error you could use the following, which would cause it to return the error,\nand then terminate all walking. This might be desirable where any error indicates a total failure.\n\n```go\nerrorHandler := func(e error) bool {\n    fileWalker.Terminate()\n    return false\n}\nfileWalker.SetErrorHandler(errorHandler)\n```\n\n### Testing\n\nDone through unit/integration tests. Otherwise see https://github.com/svent/gitignore-test\n\nSee `./cmd/gocodewalker/main.go` for an example of how to implement and validate \n\n### Info\n\nDetails on how gitignores work\n\nhttps://stackoverflow.com/questions/71735516/proper-way-to-setup-multiple-gitignore-files-in-nested-folders-of-a-repository\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboyter%2Fgocodewalker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboyter%2Fgocodewalker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboyter%2Fgocodewalker/lists"}