neato
parent
a82e9380df
commit
6704fc8302
|
|
@ -1,4 +1,5 @@
|
||||||
*.key
|
*.key
|
||||||
|
simpleserve
|
||||||
*.crt
|
*.crt
|
||||||
*.pem
|
*.pem
|
||||||
*.swp
|
*.swp
|
||||||
|
|
|
||||||
24
main.go
24
main.go
|
|
@ -9,26 +9,26 @@ listing file.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"local/args"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"strings"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
exePath, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
fs := args.NewArgSet()
|
||||||
if err != nil {
|
fs.Append(args.STRING, "p", "port to serve", "8100")
|
||||||
|
fs.Append(args.STRING, "d", "static path to serve", "./public")
|
||||||
|
if err := fs.Parse(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
port := flag.String("p", "8100", "port to serve on")
|
d := fs.Get("d").GetString()
|
||||||
directory := flag.String("d", path.Join(exePath, "public"), "the directory of static file to host")
|
p := strings.TrimPrefix(fs.Get("p").GetString(), ":")
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
http.Handle("/", http.FileServer(http.Dir(*directory)))
|
http.Handle("/", http.FileServer(http.Dir(d)))
|
||||||
|
|
||||||
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
|
log.Printf("Serving %s on HTTP port: %s\n", d, p)
|
||||||
log.Fatal(http.ListenAndServe(":"+*port, nil))
|
|
||||||
|
log.Fatal(http.ListenAndServe(":"+p, nil))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue