Related to this question, I have some Golang code here. Currently, the localhost:8080/search-availability
renders properly. Its content is as follows:
If I were to change line 13 of templates\search-availability.page.tmpl
:
<input type="text" name="csrf_token" value="{{.CsrfToken}}">
into:
<input type="text" name="csrf_token" value="{{.WrongToken}}">
anything below Search for Availability
will disappear.
To debug the issue mentioned in the other question, I want to do a rename in pkg\models\templatedata.go
:
type TemplateData struct {
StringMap map[string]string
IntMap map[string]int
FloatMap map[string]float64
Data map[string]interface{}
// CsrfToken string
Token string
Flash string
Error string
}
Basically, CsrfToken
gets shortened into Token
. To accommodate the change, line 13 of templates\search-availability.page.tmpl
is changed into:
<!-- <input type="text" name="csrf_token" value="{{.CsrfToken}}"> -->
<input type="text" name="csrf_token" value="{{.Token}}">
(I only comment out the old value. This will be clear later.) Accordingly, pkg\render\render.go
has this change:
func AddDefaultData(td *models.TemplateData, r *http.Request) *models.TemplateData {
// td.CsrfToken = nosurf.Token(r)
fmt.Printf("Token before: %s\n", td.Token)
td.Token = nosurf.Token(r)
fmt.Printf("Token after: %s\n", td.Token)
return td
}
Then I run go run ./cmd/web/*.go
to see if it works. Surprisingly, everything below Search for Availability
is missing. This is the output from the terminal:
Starting a server on port :8080
2023/03/12 23:54:46 SessionLoad
2023/03/12 23:54:46 NoSurf
2023/03/12 23:54:47 Hit the page
2023/03/12 23:54:47 Availability
Token before:
Token after: ERyPRtSgyVxmtthfMD49BsysXczubQfn7SQ3+L0ntc+6PQoHlaykAYejIa6Vw4m4omkgO94tVi/YiD0baSz2yw==
VS Code
code complete can pick up td.Token
and the terminal shows that that variable exists. Why is it behaving just like when WrongToken
is used? Removing both of these lines brings back the content from Arrival
and after:
<!-- <input type="text" name="csrf_token" value="{{.CsrfToken}}"> -->
<input type="text" name="csrf_token" value="{{.Token}}">
I am at a loss here. Why is this happening? Any insight is greatly appreciated.