Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SegHaxx committed Nov 20, 2019
1 parent d1e7274 commit 363b1fe
Show file tree
Hide file tree
Showing 16 changed files with 10,496 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ezhttpd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import "flag"
import "os"
import "path/filepath"
import "fmt"
import "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)
})))
}
Loading

0 comments on commit 363b1fe

Please sign in to comment.