initial commit
This commit is contained in:
commit
bba06b2161
5
go.mod
Normal file
5
go.mod
Normal 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
2
go.sum
Normal 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
32
main.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user