Skip to content

Instantly share code, notes, and snippets.

@L04DB4L4NC3R
Created August 18, 2019 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L04DB4L4NC3R/1311c6c182138fa8d6c712a4dab3fb58 to your computer and use it in GitHub Desktop.
Save L04DB4L4NC3R/1311c6c182138fa8d6c712a4dab3fb58 to your computer and use it in GitHub Desktop.
Examinaar
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