-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (35 loc) · 742 Bytes
/
main.go
File metadata and controls
40 lines (35 loc) · 742 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
package main
import (
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
var (
port string
)
func handleCtrlC(c chan os.Signal) {
sig := <-c
log.Println("fatal: recivied ", sig)
log.Println("info: inducing graceful shutdown")
log.Fatal("info: done!")
}
func main() {
if len(os.Args) != 3 {
log.Fatal("Argument number off: provide 2 arguments")
}
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go handleCtrlC(c)
dir := os.Args[1]
log.Println("info: serving from ", dir)
http.Handle("/", http.FileServer(http.Dir(string(dir))))
if os.Args[2] == "" {
port = ":5000"
} else {
port = ":" + os.Args[2]
}
log.Println("info: running on port:", port)
log.Fatal(http.ListenAndServe(port, nil))
}