December 2017
Intermediate to advanced
316 pages
6h 58m
English
Create a project called simpleAuth in GOPATH and add a main.go file, which holds the logic for our program:
mkdir simpleAuthtouch main.py
In this program, we are going to see how we can create a session-based authentication using the Gorilla sessions package. Refer to the following code snippet:
package mainimport ( "log" "net/http" "os" "time" "github.com/gorilla/mux" "github.com/gorilla/sessions")var store =sessions.NewCookieStore([]byte(os.Getenv("SESSION_SECRET")))var users = map[string]string{"naren": "passme", "admin": "password"}// HealthcheckHandler returns the date and timefunc HealthcheckHandler(w http.ResponseWriter, r *http.Request) { session, _ := store.Get(r, "session.id") if (session.Values["authenticated"] ...Read now
Unlock full access