2023-02-09 13:36:13 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2023-02-10 10:11:02 +01:00
|
|
|
"net/http"
|
2023-02-09 13:36:13 +01:00
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"git.milar.in/milarin/adverr"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-02-10 10:11:02 +01:00
|
|
|
root = flag.String("r", ".", "root directory")
|
2023-02-09 13:36:13 +01:00
|
|
|
iface = flag.String("i", "localhost", "network interface")
|
2023-02-10 10:11:02 +01:00
|
|
|
port = flag.Uint64("p", 8080, "port")
|
2023-02-09 13:36:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
abspath, err := filepath.Abs(*root)
|
|
|
|
if err != nil {
|
|
|
|
adverr.Fatalln(err, 1)
|
|
|
|
}
|
2023-02-10 10:11:02 +01:00
|
|
|
*root = abspath
|
|
|
|
|
|
|
|
fmt.Printf("Root Directory: %s\nURL: http://%s:%d/\n", *root, *iface, *port)
|
2023-02-09 13:36:13 +01:00
|
|
|
|
|
|
|
connStr := fmt.Sprintf("%s:%d", *iface, *port)
|
2023-02-10 10:11:02 +01:00
|
|
|
handler := LogHandler(http.FileServer(http.Dir(*root)))
|
|
|
|
|
2023-02-09 13:36:13 +01:00
|
|
|
if err := http.ListenAndServe(connStr, handler); err != nil {
|
|
|
|
adverr.Fatalln(err, 1)
|
|
|
|
}
|
|
|
|
}
|