由于没有HTTP重定向,导致执行模板提交问题?

I am trying to pass data from one page to another utilizing go. Here is a simplified version of what I am doing:

//Attempting to go from page1.gohtml to page2.gohtml to page3.gohtml.

type myData stuct {
    data1 string
    data2 string
}

func page1(w http.ResposneWriter, r *http.Request) {
    if r.Method != http.MethodPost {
        myTemplate.ExecuteTemplate(w, "page1.gohtml", my_data) //do current page
    }

   //populated myData

    myTemplate.ExecuteTemplate(w, "page2.gohtml", my_data) //go to next page
}

//My .gohtml forms are like so:
<form id="page1" name="page1" method="post">
    <input type="submit" class="click">
</form>

Repeat general code for page 2 to page 3.

Problem Statement: When I do template execution from page 1 to page 2, my data struct remains populated, the page however, remains on localhost:80/page1

It does not move to page 2 despite displaying page 2.

This isn't a problem until I go to execute the submit on page 2. This brings me back to page 1 instead of taking me to page 3.

I have tried setting my form with an action taking to take me to the next page. This redirects me, but does not bring me the populated my data structure that I need.

Setting the submit to return false stops my server code from executing.

And doing an HTTP Redirect brings me to the next page but has the same issue as the form action.

This is temporary data that I do not want to save to a Database.

Could someone help direct me on my options?

As I see it, you don't redirect, you just execute the page2 template.

For redirecting, try:

http.Redirect(w, r, "http://127.0.0.1/page2", 301)

instead of

myTemplate.ExecuteTemplate(w, "page2.gohtml", my_data) //go to next page

edit:

I see now that I didn't fully answered your question, since I ignored my_data (which by the way, in golang the named are camelCase, so you should rename it with myDate... :).

Anyway, for passing the data, since it's only strings, you can try to serialize it and add it to the request body (I don't know if it's the best practice, it's just the first thing that pop into my head that will probably work)