Created
April 8, 2017 20:08
-
-
Save ravidelcj/b5e29beae94bfe3d7bd96890f4b3ceff to your computer and use it in GitHub Desktop.
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 ( | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"io" | |
) | |
func getFile(res http.ResponseWriter, req *http.Request) { | |
files, _ := ioutil.ReadDir("./publicFolder/") | |
res.Header().Set("Content-Type", "text/html; charset=utf-8") | |
myHtml := ` | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title> | |
Home Network | |
</title> | |
</head> | |
<body> | |
<ul>` | |
for _, f := range files { | |
fmt.Println(f.Name()) | |
myHtml += (` | |
<li> | |
<a href="./publicFolder/` + f.Name() + `" download="`+f.Name()+`" >` + f.Name() + `</a> | |
</li>`) | |
} | |
// | |
myHtml += ( | |
` | |
</ul> | |
</body> | |
</html> | |
`) | |
io.WriteString(res, myHtml) | |
} | |
func main() { | |
http.HandleFunc("/getFile/", getFile) | |
http.Handle("/getFile/publicFolder/", http.StripPrefix("/getFile/publicFolder/", http.FileServer(http.Dir("./publicFolder")))) | |
http.ListenAndServe(":8008", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment