initial commit

This commit is contained in:
milarin 2023-02-09 13:36:13 +01:00
commit bba06b2161
3 changed files with 39 additions and 0 deletions

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.milar.in/milarin/httpserver
go 1.19
require git.milar.in/milarin/adverr v1.1.0

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
git.milar.in/milarin/adverr v1.1.0 h1:jD9WnOvs40lfMhvqQ7cllOaRJNBMWr1f07/s9jAadp0=
git.milar.in/milarin/adverr v1.1.0/go.mod h1:joU9sBb7ySyNv4SpTXB0Z4o1mjXsArBw4N27wjgzj9E=

32
main.go Normal file
View File

@ -0,0 +1,32 @@
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)
}
}