// GetSession implements the http.Handler interface. // // The method responds with JSON-encoded api.Session value. // // GetSession validates the authentication - for every // api.Session it reads from requests, the session must // already exist in Sessions map. Otherwise handler // responds with 401. func (fa *FakeAuth) GetSession(w http.ResponseWriter, r *http.Request) { var req api.Session req.ReadFrom(r) var session *api.Session fa.mu.RLock() for _, s := range fa.Sessions { if s.ClientID == req.ClientID { session = s break } } fa.mu.RUnlock() if session == nil { w.WriteHeader(http.StatusUnauthorized) } else { json.NewEncoder(w).Encode(session) } }