Browse Source

Display hostname in link

Replaced localhost with hostname when printing local server link
master
phoenix 1 year ago
parent
commit
5ff3cf6cbd
  1. 6
      README.md
  2. 10
      quickshare.go

6
README.md

@ -18,8 +18,10 @@ Requirements: `go > 1.9`
To share the file `README.md`
$ quickshare README.md
Serving: README.md (/home/phoenix/Projects/quickshare/README.md)
2019/09/13 16:37:40 Started http://hostname:8249
Adding more files by simply running `quickshare` again
Adding more files by simply running `quickshare` again in another window
$ quickshare LICENSE
@ -27,7 +29,7 @@ Adding more files by simply running `quickshare` again
$ quickshare README.md
Serving: README.md (/home/phoenix/Projects/quickshare/README.md)
2019/09/13 16:37:40 Started http://localhost:8249
2019/09/13 16:37:40 Started http://hostname:8249
# Notice

10
quickshare.go

@ -380,7 +380,7 @@ func main() {
if arg[0] == '-' {
if arg == "-h" || arg == "--help" {
fmt.Println("quickshare - Quick file share server")
fmt.Println(" 2019, Felix Niederwanger\n")
fmt.Println(" 2020, Felix Niederwanger\n")
fmt.Printf("Usage: %s [OPTIONS] [FILES]\n", os.Args[0])
fmt.Println("OPTIONS")
fmt.Println(" -h, --help Print this help message")
@ -497,7 +497,13 @@ func main() {
go udpServer(port)
http.HandleFunc("/", httpHandler);
log.Printf("Started http://localhost:%d\n", port)
hostname, err := os.Hostname()
if err == nil {
log.Printf("Started http://%s:%d\n", hostname, port)
} else {
fmt.Fprintln(os.Stderr," Cannot determine hostanme: ", err)
log.Printf("Started http://localhost:%d\n", port)
}
http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
}
}

Loading…
Cancel
Save