Created
August 18, 2019 02:48
-
-
Save L04DB4L4NC3R/1311c6c182138fa8d6c712a4dab3fb58 to your computer and use it in GitHub Desktop.
Examinaar
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 ( | |
"html/template" | |
"log" | |
"net/http" | |
) | |
// Setting up static file handler and HTTP server to listen and serve | |
func main() { | |
// handle requests to static files | |
http.Handle("/img/", http.FileServer(http.Dir("public"))) | |
http.Handle("/js/", http.FileServer(http.Dir("public"))) | |
http.Handle("/css/", http.FileServer(http.Dir("public"))) | |
http.Handle("/vendor/", http.FileServer(http.Dir("public"))) | |
log.Fatal(http.ListenAndServe(":3000", nil)) | |
} | |
The populateTemplates function is used for setting up templating in our program, which makes it easier for us to send and display data to the frontend | |
// Setting up templating for the program | |
func populateTemplates() \*template.Template { | |
result := tempalate.New("index.html") | |
// Parses all .html files in /views directory as a potential template | |
template.Must(result.ParseGlob("./views/\*.html")) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment