-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (34 loc) · 926 Bytes
/
main.go
File metadata and controls
47 lines (34 loc) · 926 Bytes
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
package main
import (
"embed"
"fmt"
"net/http"
"os"
qr "github.com/mdp/qrterminal/v3"
)
const PORT int32 = 8080
var (
//go:embed web
assets embed.FS
pwd, host, addr = loadEnv()
source = resolveBase()
)
/*
TODO:
- Support for audio, pdf and binaries
- Use random string for URIs to avoid conflicts
*/
func main() {
http.HandleFunc("/", browse)
programFiles := http.FileServer(http.FS(assets))
http.Handle("/static/", http.StripPrefix("/static/", programFiles))
downloadFiles := http.FileServer(http.Dir(source))
http.Handle("/download/", http.StripPrefix("/download/", downloadFiles))
http.HandleFunc("/zip/", downloadZip)
url := fmt.Sprintf("http://%s:%d", addr, PORT)
fmt.Printf("Serving from %s on %s\n", host, url)
fmt.Printf("Base directory: %s\n\n", source)
qr.GenerateHalfBlock(url, qr.L, os.Stdout)
go http.ListenAndServe(fmt.Sprintf(":%d", PORT), nil)
fmt.Scan()
}