func (a *Application) listUsersAPI(c *echo.Context) error { loginCookie, err := c.Request().Cookie("login") if err != nil { fmt.Println("cookie was empty", err) } else { session := a.Redis.GetSession(loginCookie.Value) sUser := domain.Member{} json.Unmarshal([]byte(session), &sUser) data := domain.Data{} if sUser.Role.Name == "admin" { data = a.getUsersData() } data.User = sUser return c.JSON(http.StatusOK, data) } var m = make(map[string]string) m["Err"] = "You are not logged in or the stars don't shine for you." return c.JSON(http.StatusForbidden, m) }
func (a *Application) getUsersData() domain.Data { data := domain.Data{} data.Users = a.Redis.ListUsers() return data }