Hey everyone! I am dying and full on Q_Q with this exercise lol.
I have a Kubernetes demo for the folks at work. All that is working fine, but I thought “It would be cool to have the hostname show up on the web page.”
REST. IN. PEACE. lmao
I have never struggled with something so much. I have very little experience with front-end, so I apologize in advance for low quality code (a lot has been removed in the name of brevity):
The server:
type HostInfo struct {
Name string
}
h, _ := os.Hostname()
host := HostInfo{}
host.Name = h
err = tpl.ExecuteTemplate(w, "layout", host)
That definitely seems to work, but it prints the hostname to the console. I was hoping to have it show up in a <p> or <h1> on the actual *.gohtml page.
Because the template renders to os.Stdout directly.
What it should show you, is that the way to use the context within the template is {{.Name}}.
For whatever else you have tried, but didn’t work, it would be nice if you would have told us, what exactly “didn’t work” means, in terms of actual output vs. expected output, whereas errs value should be part of actual/expected output.
I resolved the issue, I was using separate ExecuteTemplate for “/” vs “/status”. Once I referenced the struct in the first ExecuteTemplate, it worked on all pages.