-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (32 loc) · 729 Bytes
/
main.go
File metadata and controls
38 lines (32 loc) · 729 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
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"path"
)
func main() {
// Parse flags
var port = flag.Int("port", 9100, "port for the server")
var dir = flag.String("dir", "files", "folder to collect")
flag.Parse()
// Handle HTTP on /
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// Read list of files in dir
files, err := ioutil.ReadDir(*dir)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
for _, file := range files {
b, err := ioutil.ReadFile(path.Join(*dir, file.Name()))
if err != nil {
continue
}
fmt.Fprintf(w, string(b))
}
})
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", *port), nil))
}