-
-
Save juneym/40d3ebd7cb1c2465212a to your computer and use it in GitHub Desktop.
Share you directory via http server by golang.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"strconv" | |
) | |
func main() { | |
dir := flag.String("dir", "", "Directory path you want to share (start with / or ./)") | |
port := flag.Int("port", 8080, "Port number to listen") | |
flag.Parse() | |
if *dir == "" { | |
flag.Usage() | |
return | |
} | |
h := http.FileServer(http.Dir(*dir)) | |
fmt.Scanf("%s", &port) | |
fmt.Println("Listening to 0.0.0.0:" + strconv.Itoa(*port) + "\n") | |
err := http.ListenAndServe(":"+strconv.Itoa(*port), h) | |
if err != nil { | |
log.Fatal("ListenAndServe: ", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment