models.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "github.com/torkelo/grafana-pro/pkg/models"
  7. )
  8. type LoginResult struct {
  9. Status string `json:"status"`
  10. User CurrentUser `json:"user"`
  11. }
  12. type CurrentUser struct {
  13. Login string `json:"login"`
  14. Email string `json:"email"`
  15. GravatarUrl string `json:"gravatarUrl"`
  16. }
  17. type DataSource struct {
  18. Id int64 `json:"id"`
  19. AccountId int64 `json:"accountId"`
  20. Name string `json:"name"`
  21. Type models.DsType `json:"type"`
  22. Access models.DsAccess `json:"access"`
  23. Url string `json:"url"`
  24. Password string `json:"password"`
  25. User string `json:"user"`
  26. Database string `json:"database"`
  27. BasicAuth bool `json:"basicAuth"`
  28. IsDefault bool `json:"isDefault"`
  29. }
  30. type MetricQueryResultDto struct {
  31. Data []MetricQueryResultDataDto `json:"data"`
  32. }
  33. type MetricQueryResultDataDto struct {
  34. Target string `json:"target"`
  35. DataPoints [][2]float64 `json:"datapoints"`
  36. }
  37. func NewCurrentUser(account *models.Account) *CurrentUser {
  38. model := &CurrentUser{}
  39. if account != nil {
  40. model.Login = account.Login
  41. model.Email = account.Email
  42. model.GravatarUrl = getGravatarUrl(account.Email)
  43. }
  44. return model
  45. }
  46. func getGravatarUrl(text string) string {
  47. hasher := md5.New()
  48. hasher.Write([]byte(strings.ToLower(text)))
  49. return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
  50. }