mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 15:29:26 +00:00
34 lines
648 B
Go
34 lines
648 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"mime"
|
|
"net/http"
|
|
"path/filepath"
|
|
)
|
|
|
|
func main() {
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
file := "../public" // base directory
|
|
|
|
if r.URL.Path == "/" {
|
|
file = file + "/index.html" // default
|
|
} else {
|
|
file = file + r.URL.Path // request
|
|
}
|
|
|
|
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("-------------")
|
|
|
|
http.ServeFile(w, r, file) // serve file
|
|
})
|
|
|
|
log.Fatal(http.ListenAndServe(":6970", nil))
|
|
}
|