summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorhorus_arch2015-06-15 13:38:47 +0200
committerhorus_arch2015-06-15 13:38:47 +0200
commitc79e605b60040c4c0e5c792fa447487c2b8ae246 (patch)
treed20c97b59c6252e555618a128ea63f6fa9d016d9 /main.go
parent3a09b2509102d58fe4e52a9a8fa699f6b42dc327 (diff)
downloaduhttpd-c79e605b60040c4c0e5c792fa447487c2b8ae246.tar.gz
Use flex to extract html. Icono-font used for icons.
Diffstat (limited to 'main.go')
-rw-r--r--main.go36
1 files changed, 35 insertions, 1 deletions
diff --git a/main.go b/main.go
index c17edd1..fd2189f 100644
--- a/main.go
+++ b/main.go
@@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"log"
+ "net"
"net/http"
"os"
)
@@ -19,6 +20,8 @@ func accessLog(h http.Handler, quiet bool) http.Handler {
return http.HandlerFunc(fn)
}
+var _allow_upload bool // todo: inject as dependency
+
func main() {
ip_f := flag.String("ip", "0.0.0.0", "IP adress to listen on.")
port_f := flag.String("port", "3000", "Port to listen on.")
@@ -35,13 +38,44 @@ func main() {
}
if !*quiet_f {
- fmt.Println("Starting uhttpd serving \"" + *dir_f + "\" on " + *ip_f + ":" + port + ".")
+ fmt.Print("You started µhttpd listening on " + *ip_f + ":" + port + " serving \"" + *dir_f + "\" as content.")
+ if !*disallow_upl_f {
+ fmt.Println(" Upload is enabled and accessible under /upload.")
+ } else {
+ fmt.Println(" Upload is disabled.")
+ }
+ fmt.Print("To view open your browser and try to open this as a url: ")
+
+ if *ip_f == "0.0.0.0" {
+ addrs, err := net.InterfaceAddrs()
+ if err != nil {
+ log.Fatal(err)
+ return
+ }
+
+ for cnt, adr := range addrs {
+ if ipnet, ok := adr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
+ if ipnet.IP.To4() != nil {
+ if cnt > 1 {
+ fmt.Printf(" or http://%s:%s/", ipnet.IP.String(), port)
+ } else {
+ fmt.Printf("http://%s:%s/", ipnet.IP.String(), port)
+ }
+ }
+ }
+ }
+ } else {
+ fmt.Print("http://" + *ip_f + ":" + port + "/")
+ }
+ fmt.Print("\n\n")
+
}
mux := http.NewServeMux()
if !*disallow_upl_f {
os.MkdirAll(*upl_dir_f, 0755)
mux.Handle("/upload", uploadHandler(*upl_dir_f, *quiet_f))
+ _allow_upload = true
}
mux.Handle("/", accessLog(http.FileServer(http.Dir(*dir_f)), *quiet_f))
log.Fatal(http.ListenAndServe(*ip_f+":"+port, mux))