-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathezhttpd.go
42 lines (35 loc) · 946 Bytes
/
ezhttpd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2019 Seg <[email protected]>
package main
import "flag"
import "os"
import "path/filepath"
import "fmt"
import "github.com/SegHaxx/ezhttpd/http"
func main(){
flag.Usage = func() {
fmt.Println("Usage:",filepath.Base(os.Args[0]),"[options] [path to share]")
flag.PrintDefaults()
}
bind := flag.String("bind",":9000","Bind address")
flag.Parse()
webroot := flag.Arg(0)
if webroot == "" {
tmp, err := os.Getwd()
if err != nil {return}
webroot = tmp
}
webroot = filepath.Clean(webroot)
hostname := ""
if (*bind)[0] == ':' {
tmp, err := os.Hostname()
if err == nil {
hostname = tmp
}}
fmt.Print("Sharing ",webroot," on http://",hostname,*bind,"/\n")
http.Handle("/", http.FileServer(http.Dir(webroot)))
fmt.Println(http.ListenAndServe((*bind),
http.HandlerFunc(func(w http.ResponseWriter,r *http.Request){
http.DefaultServeMux.ServeHTTP(w,r)
fmt.Println(r.RemoteAddr,r.Method,r.URL.Path)
})))
}