Reputation: 119
I just don't understand Go templates and relative paths...
Using the following directory structure:
Application Directory
program.go
program executable
-- css
program.css
-- pages
index.gohtml
wartree.gohtml
At this point, my templates are pure html that has been in use in different environments for several years.
I have the following Go code:
package main
import (
"fmt"
"log"
"net/http"
"html/template"
)
func main() {
http.HandleFunc("/", index)
http.HandleFunc("/wartree", wartree)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func index(w http.ResponseWriter, r *http.Request) {
fmt.Println("Index has been called...")
tmpl := template.Must(template.ParseGlob("pages/*"))
tmpl.Execute(w, nil)
}
func wartree(w http.ResponseWriter, r *http.Request) {
fmt.Println("wartree has been called...")
tmpl := template.Must(template.ParseFiles("wartree.gohtml"))
tmpl.Execute(w, nil)
}
Both templates have the following line in the HTML template heads...<link href="css/nav.css" type="text/css" media="screen" />
When I execute the program, the css is not used and I cannot call the Wartree template. It just calls index again???
I even tried changing the path to the css to be absolute but that made no difference, and I see no errors from Go or the browser.
I just simply don't get Go templates and paths. I guess.
Upvotes: 0
Views: 1332