The backend for the project formerly known as signet, now known as beignet.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637
  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/imosed/signet/auth"
  6. . "github.com/imosed/signet/data"
  7. )
  8. type GetUsersResponse struct {
  9. Users []User `json:"users"`
  10. }
  11. func GetUsers(w http.ResponseWriter, r *http.Request) {
  12. claims, err := auth.GetUserClaims(r)
  13. if claims == nil {
  14. w.WriteHeader(401)
  15. return
  16. }
  17. if claims.Privileges > AdminPlus {
  18. w.WriteHeader(403)
  19. return
  20. }
  21. var users []User
  22. Db.Table("users").Where("privileges >= ?", claims.Privileges).Order("id").Scan(&users)
  23. var resp GetUsersResponse
  24. resp.Users = users
  25. err = json.NewEncoder(w).Encode(resp)
  26. if err != nil {
  27. panic("Could not deliver response")
  28. }
  29. }