为什么当我再次运行main.go时视图相同

main.go

package main
import (
    "html/template"
    "net/http"
)
var templates = template.Must(template.ParseGlob("./templates/*"))

    func viewHandler(w http.ResponseWriter, r *http.Request) {
    err := templates.ExecuteTemplate(w, "indexPage", nil)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
}

func main() {
    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
    http.HandleFunc("/index", viewHandler)
    http.ListenAndServe(":8090", nil)
}

index.html

{{define "indexPage"}}
<html>
{{template "header"}}
<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">Welcome to TDT Project</a>
            </div>
        </div>
    </nav>

    <div class="btn-group-vertical">
        <a href="#" class="btn btn-default">Button</a>
        <a href="#" class="btn btn-default">Button</a>
    </div>
</body>
</html>
{{end}}

another html file is header.html and is correct.

When I change the html and run main.go again, why the views are always the same?(I have cleaned the cache of browser)For example, change "Welcome" to "wwww", the browser does change at all.

Then I kill the progress of main.go and run it again, the view is changed.

Is there a better way to stop the main.go rather than kill this progress?

You are rendering your templates only once as templates is a global variable.

To re-render your templates each time you can move the rendering to your function. This however is bad for performance as rendering is quite expensive but it's ok during development. As an alternative you can for example use what @elithrar proposed. A further alternative would be to use gin and modify it to also scan for html files and not only go files.