models.go 996 B

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