-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathmain.go
42 lines (34 loc) · 909 Bytes
/
main.go
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
//go:generate go run github.com/UnnoTed/fileb0x b0x.yaml
package main
import (
"log"
"net/http"
// "example.com/foo/simple" represents your package (as per go.mod)
// package static is created by `go generate` according to b0x.yaml (as per the comment above)
"example.com/foo/simple/static"
)
func main() {
files, err := static.WalkDirs("", false)
if err != nil {
log.Fatal(err)
}
log.Println("ALL FILES", files)
b, err := static.ReadFile("public/README.md")
if err != nil {
log.Fatal(err)
}
_ = b
//log.Println(string(b))
log.Println("try it -> http://localhost:8080/public/secrets.txt")
// false = file system
// true = handler
as := false
// try it -> http://localhost:8080/public/secrets.txt
if as {
// as Handler
panic(http.ListenAndServe(":8080", static.Handler))
} else {
// as File System
panic(http.ListenAndServe(":8080", http.FileServer(static.HTTP)))
}
}