From 0e8ba8633a6c15415716cfbd254e70585539f4ae Mon Sep 17 00:00:00 2001 From: xinyu Date: Sat, 21 Feb 2026 17:48:05 +0800 Subject: [PATCH] init --- main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.go b/main.go index 293eec8..add537b 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net/http" "github.com/spf13/afero" ) @@ -42,4 +43,14 @@ func main() { if _, err := bfs.Open("/etc/passwd"); err != nil { fmt.Println(err.Error()) } + + //当作http.FileSystem + memFs := afero.NewMemMapFs() + afero.WriteFile(memFs, "index.html", []byte("

Afero in web

"), 0644) + + httpFs := afero.NewHttpFs(memFs) + http.Handle("/", http.FileServer(httpFs)) + //显示index.html文件内容 + + http.ListenAndServe(":8080", nil) }