-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpgogo.go
36 lines (31 loc) · 950 Bytes
/
httpgogo.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
package main
import (
"flag"
"fmt"
"net/http"
"os"
"os/signal"
)
func main() {
// Open a channel for signal processing
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
go func() {
for sig := range c {
fmt.Println("Signal received:", sig)
fmt.Println("Exiting...")
os.Exit(0)
}
}()
// Get the command-line arguments
argPort := flag.Int("port", 8080, "The port to run httpgogo on. Defaults to 8080.")
argPath := flag.String("path", "./", "The path to serve. Defaults to the current directory.")
flag.Parse()
// Give the user some kind of feedback
fmt.Println(fmt.Sprintf("Starting static file server at %s on port %v", *argPath, *argPort))
// Start the server on argPort, using FileServer at argPath as the handler
err := http.ListenAndServe(fmt.Sprintf(":%v", *argPort), http.FileServer(http.Dir(*argPath)))
if err != nil {
fmt.Println("Error running web server for static assets:", err)
}
}