httpserver/main.go

33 lines
636 B
Go
Raw Normal View History

2023-02-09 13:36:13 +01:00
package main
import (
"net/http"
"flag"
"fmt"
"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)
}
fmt.Printf("Root Directory: %s\nURL: http://%s:%d/\n", abspath, *iface, *port)
connStr := fmt.Sprintf("%s:%d", *iface, *port)
handler := http.FileServer(http.Dir(*root))
if err := http.ListenAndServe(connStr, handler); err != nil {
adverr.Fatalln(err, 1)
}
}