init
This commit is contained in:
parent
117c2be9de
commit
0e8ba8633a
11
main.go
11
main.go
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
)
|
)
|
||||||
|
|
@ -42,4 +43,14 @@ func main() {
|
||||||
if _, err := bfs.Open("/etc/passwd"); err != nil {
|
if _, err := bfs.Open("/etc/passwd"); err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//当作http.FileSystem
|
||||||
|
memFs := afero.NewMemMapFs()
|
||||||
|
afero.WriteFile(memFs, "index.html", []byte("<h1>Afero in web</h1>"), 0644)
|
||||||
|
|
||||||
|
httpFs := afero.NewHttpFs(memFs)
|
||||||
|
http.Handle("/", http.FileServer(httpFs))
|
||||||
|
//显示index.html文件内容
|
||||||
|
|
||||||
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue