Skip to content

Commit bd4f4e7

Browse files
claudemrjoshuak
authored andcommitted
Improve repository health and maintainability
- Fix invalid Go version (1.25.4 -> 1.23) to match CI configuration - Add .gitignore for Go projects (binaries, coverage, IDE files) - Replace deprecated ioutil.ReadAll with io.ReadAll - Fix comment spacing to follow Go conventions - Enhance README with badges, examples, and comprehensive documentation - Rename Readme.md to README.md for consistency
1 parent f87923f commit bd4f4e7

File tree

6 files changed

+176
-13
lines changed

6 files changed

+176
-13
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
*.out
13+
coverage.out
14+
15+
# Dependency directories
16+
vendor/
17+
18+
# Go workspace file
19+
go.work
20+
21+
# IDE and editor files
22+
.vscode/
23+
.idea/
24+
*.swp
25+
*.swo
26+
*~
27+
28+
# OS files
29+
.DS_Store
30+
Thumbs.db

README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# httpfs
2+
3+
[![CI](https://github.com/absfs/httpfs/actions/workflows/ci.yml/badge.svg)](https://github.com/absfs/httpfs/actions/workflows/ci.yml)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/absfs/httpfs)](https://goreportcard.com/report/github.com/absfs/httpfs)
5+
[![GoDoc](https://godoc.org/github.com/absfs/httpfs?status.svg)](https://godoc.org/github.com/absfs/httpfs)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7+
8+
The `httpfs` package implements a `net/http` FileSystem interface compatible object that includes both file reading and file writing operations. It provides a bridge between the [absfs](https://github.com/absfs/absfs) filesystem abstraction and Go's standard `http.FileServer`.
9+
10+
## Features
11+
12+
- Implements `http.FileSystem` interface for serving files over HTTP
13+
- Full read/write filesystem operations (Open, OpenFile, Mkdir, Remove, etc.)
14+
- Compatible with any `absfs.Filer` implementation
15+
- Supports recursive directory operations (MkdirAll, RemoveAll)
16+
- File metadata operations (Stat, Chmod, Chtimes, Chown)
17+
18+
## Installation
19+
20+
```bash
21+
go get github.com/absfs/httpfs
22+
```
23+
24+
## Usage
25+
26+
### Basic HTTP File Server
27+
28+
```go
29+
package main
30+
31+
import (
32+
"log"
33+
"net/http"
34+
35+
"github.com/absfs/httpfs"
36+
"github.com/absfs/memfs"
37+
)
38+
39+
func main() {
40+
// Create an in-memory filesystem
41+
mfs, err := memfs.NewFS()
42+
if err != nil {
43+
log.Fatal(err)
44+
}
45+
46+
// Wrap it with httpfs
47+
fs := httpfs.New(mfs)
48+
49+
// Serve files over HTTP
50+
http.Handle("/", http.FileServer(fs))
51+
log.Fatal(http.ListenAndServe(":8080", nil))
52+
}
53+
```
54+
55+
### File Operations
56+
57+
```go
58+
package main
59+
60+
import (
61+
"log"
62+
"os"
63+
64+
"github.com/absfs/httpfs"
65+
"github.com/absfs/memfs"
66+
)
67+
68+
func main() {
69+
// Create filesystem
70+
mfs, _ := memfs.NewFS()
71+
fs := httpfs.New(mfs)
72+
73+
// Create a directory
74+
if err := fs.MkdirAll("/path/to/dir", 0755); err != nil {
75+
log.Fatal(err)
76+
}
77+
78+
// Create and write to a file
79+
f, err := fs.OpenFile("/path/to/file.txt", os.O_CREATE|os.O_RDWR, 0644)
80+
if err != nil {
81+
log.Fatal(err)
82+
}
83+
defer f.Close()
84+
85+
f.Write([]byte("Hello, World!"))
86+
87+
// Get file info
88+
info, err := fs.Stat("/path/to/file.txt")
89+
if err != nil {
90+
log.Fatal(err)
91+
}
92+
log.Printf("File size: %d bytes", info.Size())
93+
}
94+
```
95+
96+
## API
97+
98+
### Core Methods
99+
100+
- `New(fs absfs.Filer) *Httpfs` - Creates a new HTTP filesystem wrapper
101+
- `Open(name string) (http.File, error)` - Opens a file for reading
102+
- `OpenFile(name string, flag int, perm os.FileMode) (absfs.File, error)` - Opens a file with flags
103+
104+
### Directory Operations
105+
106+
- `Mkdir(name string, perm os.FileMode) error` - Creates a directory
107+
- `MkdirAll(name string, perm os.FileMode) error` - Creates all directories in path
108+
- `Remove(name string) error` - Removes a file or empty directory
109+
- `RemoveAll(path string) error` - Recursively removes a directory and its contents
110+
111+
### Metadata Operations
112+
113+
- `Stat(name string) (os.FileInfo, error)` - Returns file information
114+
- `Chmod(name string, mode os.FileMode) error` - Changes file mode
115+
- `Chtimes(name string, atime time.Time, mtime time.Time) error` - Changes access/modification times
116+
- `Chown(name string, uid, gid int) error` - Changes file owner and group
117+
118+
## Requirements
119+
120+
- Go 1.22 or higher
121+
122+
## Testing
123+
124+
```bash
125+
go test -v ./...
126+
```
127+
128+
## License
129+
130+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
131+
132+
## Contributing
133+
134+
Contributions are welcome! Please feel free to submit a Pull Request.
135+
136+
## Related Projects
137+
138+
- [absfs](https://github.com/absfs/absfs) - Abstract filesystem interface for Go
139+
- [memfs](https://github.com/absfs/memfs) - In-memory filesystem implementation

Readme.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/absfs/httpfs
22

3-
go 1.25.4
3+
go 1.23
44

55
require (
66
github.com/absfs/absfs v0.0.0-20251109181304-77e2f9ac4448

httpfs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ func (filer *Httpfs) Stat(name string) (os.FileInfo, error) {
107107
return filer.fs.Stat(name)
108108
}
109109

110-
//Chmod changes the mode of the named file to mode.
110+
// Chmod changes the mode of the named file to mode.
111111
func (filer *Httpfs) Chmod(name string, mode os.FileMode) error {
112112
return filer.fs.Chmod(name, mode)
113113
}
114114

115-
//Chtimes changes the access and modification times of the named file
115+
// Chtimes changes the access and modification times of the named file
116116
func (filer *Httpfs) Chtimes(name string, atime time.Time, mtime time.Time) error {
117117
return filer.fs.Chtimes(name, atime, mtime)
118118
}
119119

120-
//Chown changes the owner and group ids of the named file
120+
// Chown changes the owner and group ids of the named file
121121
func (filer *Httpfs) Chown(name string, uid, gid int) error {
122122
return filer.fs.Chown(name, uid, gid)
123123
}

httpfs_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package httpfs_test
22

33
import (
4-
"io/ioutil"
4+
"io"
55
"log"
66
"net/http"
77
"net/http/httptest"
88
"os"
9+
"testing"
910

1011
"github.com/absfs/httpfs"
1112
"github.com/absfs/memfs"
12-
13-
"testing"
1413
)
1514

1615
func TestFileServer(t *testing.T) {
@@ -38,7 +37,7 @@ func TestFileServer(t *testing.T) {
3837
if err != nil {
3938
log.Fatal(err)
4039
}
41-
data, err := ioutil.ReadAll(res.Body)
40+
data, err := io.ReadAll(res.Body)
4241
res.Body.Close()
4342
if string(data) != "foo bar bat." {
4443
t.Fatal("wrong response")

0 commit comments

Comments
 (0)