{"id":27135539,"url":"https://github.com/go-universal/fs","last_synced_at":"2025-04-10T00:08:45.173Z","repository":{"id":286602662,"uuid":"961914134","full_name":"go-universal/fs","owner":"go-universal","description":"📁 Flexible embed and local file system for Go.","archived":false,"fork":false,"pushed_at":"2025-04-07T11:39:30.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T00:08:42.019Z","etag":null,"topics":["embedded-files","filesystem","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-universal.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":"2025-04-07T11:13:30.000Z","updated_at":"2025-04-08T09:31:35.000Z","dependencies_parsed_at":"2025-04-07T12:42:48.063Z","dependency_job_id":null,"html_url":"https://github.com/go-universal/fs","commit_stats":null,"previous_names":["go-universal/fs"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Ffs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Ffs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Ffs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Ffs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-universal","download_url":"https://codeload.github.com/go-universal/fs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131317,"owners_count":21052819,"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":["embedded-files","filesystem","golang"],"created_at":"2025-04-08T01:48:35.859Z","updated_at":"2025-04-10T00:08:45.150Z","avatar_url":"https://github.com/go-universal.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flexible File System\n\n![GitHub Tag](https://img.shields.io/github/v/tag/go-universal/fs?sort=semver\u0026label=version)\n[![Go Reference](https://pkg.go.dev/badge/github.com/go-universal/fs.svg)](https://pkg.go.dev/github.com/go-universal/fs)\n[![License](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/go-universal/fs/blob/main/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/go-universal/fs)](https://goreportcard.com/report/github.com/go-universal/fs)\n![Contributors](https://img.shields.io/github/contributors/go-universal/fs)\n![Issues](https://img.shields.io/github/issues/go-universal/fs)\n\nThe `fs` package provides a flexible file system abstraction for working with both local and embedded file systems. It offers various utilities for file operations such as checking existence, reading files, searching, and more.\n\n## Installation\n\nTo use the `fs` package, add it to your Go project:\n\n```bash\ngo get github.com/go-universal/fs\n```\n\n## Features\n\n- Support for both local and embedded file systems.\n- File existence checks.\n- File reading and opening.\n- Searching for files by patterns or content.\n- Lookup for multiple files matching a pattern.\n- Integration with `fs.FS` and `http.FileSystem`.\n\n## Usage\n\nCreates a `FlexibleFS` instance backed by the local file system at the specified directory path.\n\n```go\nfs := fs.NewDir(\".\")\n```\n\nCreates a `FlexibleFS` instance backed by the provided embedded file system.\n\n```go\n//go:embed *.go\nvar embeds embed.FS\n\nfs := fs.NewEmbed(embeds)\n```\n\n## Exists\n\nChecks if a file with the given name exists in the file system.\n\n```go\nexists, err := fs.Exists(\"file.go\")\nif err != nil {\n    log.Fatal(err)\n}\nfmt.Println(\"File exists:\", exists)\n```\n\n## Open\n\nOpens a file with the given name and returns an `fs.File` interface for reading the file.\n\n```go\nfile, err := fs.Open(\"file.go\")\nif err != nil {\n    log.Fatal(err)\n}\ndefer file.Close()\n```\n\n## ReadFile\n\nReads the entire content of the file with the given name and returns the content as a byte slice.\n\n```go\ncontent, err := fs.ReadFile(\"file.go\")\nif err != nil {\n    log.Fatal(err)\n}\nfmt.Println(string(content))\n```\n\n## Search\n\nSearches for a phrase in files within the specified directory, optionally ignoring certain files and filtering by extension.\n\n**Example:**\n\n```go\nresult, err := fs.Search(\".\", \"main\", \"\", \"go\")\nif err != nil {\n    log.Fatal(err)\n}\nif result != nil {\n    fmt.Println(\"Found:\", *result)\n} else {\n    fmt.Println(\"No match found\")\n}\n```\n\n## Find\n\nSearches for a file matching the given regex pattern in the specified directory.\n\n```go\nresult, err := fs.Find(\".\", \".*\\\\.go\")\nif err != nil {\n    log.Fatal(err)\n}\nif result != nil {\n    fmt.Println(\"Found:\", *result)\n} else {\n    fmt.Println(\"No match found\")\n}\n```\n\n## Lookup\n\nSearches for files matching the given regex pattern in the specified directory and returns a slice of matching file paths.\n\n```go\nresults, err := fs.Lookup(\".\", \".*\\\\.go\")\nif err != nil {\n    log.Fatal(err)\n}\nfmt.Println(\"Found files:\", results)\n```\n\n## FS\n\nReturns the underlying `fs.FS` interface of the file system.\n\n```go\nfsInterface := fs.FS()\n```\n\n## Http\n\nReturns the `http.FileSystem` instance of the file system.\n\n```go\nhttpFS := fs.Http()\nhttp.Handle(\"/\", http.FileServer(httpFS))\nlog.Fatal(http.ListenAndServe(\":8080\", nil))\n```\n\n## License\n\nThis project is licensed under the ISC License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-universal%2Ffs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-universal%2Ffs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-universal%2Ffs/lists"}