-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
52 lines (41 loc) · 1.13 KB
/
Copy pathexample_test.go
File metadata and controls
52 lines (41 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package zipfs_test
import (
"archive/zip"
"log"
"net/http"
"os"
"gerace.dev/zipfs"
)
func ExampleNewEmbeddedZipFileSystem() {
fs, err := zipfs.NewEmbeddedZipFileSystem()
if err != nil {
log.Fatalf("Error setting up zipfs: %v", err)
}
log.Fatal(http.ListenAndServe("127.0.0.1:8080", http.FileServer(fs)))
}
func ExampleNewZipFileSystem() {
f, err := os.Open("webassets.zip")
if err != nil {
log.Fatalf("Error opening webassets.zip: %v", err)
}
fi, err := f.Stat()
if err != nil {
log.Fatalf("Error getting file information about webassets.zip: %v", err)
}
zr, err := zip.NewReader(f, fi.Size())
if err != nil {
log.Fatalf("Error reading zip data from webassets.zip: %v", err)
}
fs, err := zipfs.NewZipFileSystem(zr)
if err != nil {
log.Fatalf("Error creating zip filesystem: %v", err)
}
log.Fatal(http.ListenAndServe("127.0.0.1:8080", http.FileServer(fs)))
}
func ExampleServeIndexForMissing() {
fs, err := zipfs.NewEmbeddedZipFileSystem(zipfs.ServeIndexForMissing())
if err != nil {
log.Fatalf("Error setting up zipfs: %v", err)
}
log.Fatal(http.ListenAndServe("127.0.0.1:8080", http.FileServer(fs)))
}