api_models.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package api
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "github.com/torkelo/grafana-pro/pkg/models"
  7. )
  8. type saveDashboardCommand struct {
  9. Id string `json:"id"`
  10. Title string `json:"title"`
  11. Dashboard map[string]interface{}
  12. }
  13. type errorResponse struct {
  14. Message string `json:"message"`
  15. }
  16. type IndexDto struct {
  17. User CurrentUserDto
  18. }
  19. type CurrentUserDto struct {
  20. Login string `json:"login"`
  21. Email string `json:"email"`
  22. GravatarUrl string `json:"gravatarUrl"`
  23. }
  24. type LoginResultDto struct {
  25. Status string `json:"status"`
  26. User CurrentUserDto `json:"user"`
  27. }
  28. func newErrorResponse(message string) *errorResponse {
  29. return &errorResponse{Message: message}
  30. }
  31. func initCurrentUserDto(userDto *CurrentUserDto, account *models.Account) {
  32. if account != nil {
  33. userDto.Login = account.Login
  34. userDto.Email = account.Email
  35. userDto.GravatarUrl = getGravatarUrl(account.Email)
  36. }
  37. }
  38. func getGravatarUrl(text string) string {
  39. hasher := md5.New()
  40. hasher.Write([]byte(strings.ToLower(text)))
  41. return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
  42. }