httpserver/main.go
2023-02-10 12:48:42 +01:00

36 lines
667 B
Go

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