mercredi 28 juillet 2021

How to manage the login and logout in golang?

In this code, I made a function called logout in which I wrote struct to check if the Logout variable is called then it should return true. I called this function in logout.html to check the if statement.

What I want to do is that if I am not logged in then it should give me the message that Please login first and if I am logged in then after clicking on logout button it should give me the else statement message.

But when visit the localhost:4000/logout even if I am logged in or not, it gives me the same message of if-statment every time.

handler.go

func logout(w http.ResponseWriter, r *http.Request) {
    d := struct{ Logout bool }{Logout: true}
    logoutTmpl.Execute(w, d)
}

logout.html


    <h1>Please login first</h1> 

    <h1>You been successfully logout</h1>

Aucun commentaire:

Enregistrer un commentaire