I'm using a template that links to a CSS file, and following some other posts on this board, I think I have everything correct, but the CSS is still not being applied. Also, when I use the Developer tools in Chrome is see the link to the CSS file as I put in in the template, and if I click on it, it takes me to the CSS file, which I assume shows me it can find the file.
Go code:
package main
import (
"fmt"
"strings"
"os"
"text/template"
"net/http"
)
var tpl *template.Template
func init() {
tpl = template.Must(template.ParseGlob("templates/*"))
}
func handler(w http.ResponseWriter, r *http.Request) {
host, _ := os.Hostname()
err := tpl.Execute(w, host)
if err != nil {
fmt.Println("Template Execute failed: ", err)
}
}
func process(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Println(r.Form)
fmt.Println("path", r.URL.Path)
fmt.Println("scheme", r.URL.Scheme)
fmt.Println(r.Form["url_long"])
for k, v := range r.Form {
fmt.Println("key:", k)
fmt.Println("val:", strings.Join(v, ""))
}
fmt.Println(r.Form["wall"])
}
func main() {
host, _ := os.Hostname()
fmt.Println("host =", host)
//err = tpl.Execute(f, host)
swall := http.NewServeMux()
//fs := http.FileServer(http.Dir("www"))
//swall.Handle("/", fs)
swall.Handle("/resources/", http.StripPrefix("/resources/", http.FileServer(http.Dir("resources"))))
swall.HandleFunc("/", handler)
swall.HandleFunc("/process", process)
http.ListenAndServe(":8080", swall)
}
HTML:
<!doctype html>
<html>
<head>
<title>Great Wall</title>
<link href="/resources/css/gwall.css" type="text/css" />
</head>
<body>
<main>
<div id="page_title">
<h1>Great Wall</h1>
</div>
</main>
</body>
</html>
CSS:
h1 {
color: red;
font-size: 36pt;
text-align: center;
}
I tried everything I can think of and searched for several days, but I don't have much experience with templates and I'm at a complete loss right now. I know when someone tells me what I'm doing wrong I'll end up smacking myself on the forehead, but at this point I'll risk the bruising. Thanks for any help.