Golang-http.Redirect无法在处理程序中重定向而不是处理发布数据

I was thinking of doing the following for the authentication.

(1) Client visits home,say http://localhost:3000 The client is shown a login form with username, password, gamecode.

(2) When the client submits this form, I use javascript to post the data to http://localhost:3000/login that accepts POST requests. In my golang file the relevant route is defined as:

rtr := mux.NewRouter()
rtr.HandleFunc("/login", loginHandler).Methods("POST")

(3) Now I want to check if the three, username, password and the gamecode are valid. I start with the gamecode, and I have no difficulty reading the value submitted and checking in against the list of valid gamecodes in the database. Now, if the gamecode is invalid, I want to redirect the user to another route. I am failing to do so. These are the relevant lines:

// I check if gamecode is valid. If it is invalid, gameCodeExists = 0
if gameCodeExists == 0 {
    // this message prints on the server as expected for an invalid code
    fmt.Println("gamecode invalid...")

    // this redirect never occurs
    http.Redirect(w, req, "/loginfail", 302)
    return
} else {
    fmt.Println("Valid code")
}

Can someone please help me with what I am doing wrong, and how I can fix it?

Thank you.