mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 07:19:26 +00:00
main.go update. Refactor: Same functionality, but better readabilty.
This commit is contained in:
parent
bf69f6cba8
commit
c514ba151e
2 changed files with 11 additions and 15 deletions
24
be/main.go
24
be/main.go
|
|
@ -9,29 +9,25 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
// log.Println(r.URL.Path)
|
|
||||||
|
|
||||||
file := "../public" + r.URL.Path
|
file := "../public" // base directory
|
||||||
|
|
||||||
if r.URL.Path == "/" {
|
if r.URL.Path == "/" {
|
||||||
file = "../public/index.html"
|
file = file + "/index.html" // default
|
||||||
// } else if strings.HasSuffix(r.URL.Path, ".js") {
|
|
||||||
// log.Println("js")
|
|
||||||
// w.Header().Set("Content-Type", "application/javascript")
|
|
||||||
// } else if strings.HasSuffix(r.URL.Path, ".css") {
|
|
||||||
// log.Println("css")
|
|
||||||
// w.Header().Set("Content-Type", "text/css")
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
contentType := mime.TypeByExtension(filepath.Ext(file))
|
file = file + r.URL.Path // request
|
||||||
if contentType != "" {
|
|
||||||
w.Header().Set("Content-Type", contentType)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentType := mime.TypeByExtension(filepath.Ext(file)) // get content type
|
||||||
|
|
||||||
|
if contentType != "" {
|
||||||
|
w.Header().Set("Content-Type", contentType) // set content type header
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(file)
|
log.Println(file)
|
||||||
log.Println("-------------")
|
log.Println("-------------")
|
||||||
http.ServeFile(w, r, file)
|
|
||||||
|
http.ServeFile(w, r, file) // serve file
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":6970", nil))
|
log.Fatal(http.ListenAndServe(":6970", nil))
|
||||||
|
|
|
||||||
BIN
be/tmp/main.exe
BIN
be/tmp/main.exe
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue