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