models.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. m "github.com/torkelo/grafana-pro/pkg/models"
  7. )
  8. type LoginCommand struct {
  9. User string `json:"user" binding:"Required"`
  10. Password string `json:"password" binding:"Required"`
  11. Remember bool `json:"remember"`
  12. }
  13. type CurrentUser struct {
  14. IsSignedIn bool `json:"isSignedIn"`
  15. Login string `json:"login"`
  16. Email string `json:"email"`
  17. Name string `json:"name"`
  18. AccountRole m.RoleType `json:"accountRole"`
  19. AccountName string `json:"acountName"`
  20. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  21. GravatarUrl string `json:"gravatarUrl"`
  22. }
  23. type Dashboard struct {
  24. IsFavorite bool `json:"isFavorite"`
  25. Dashboard map[string]interface{} `json:"dashboard"`
  26. }
  27. type DataSource struct {
  28. Id int64 `json:"id"`
  29. AccountId int64 `json:"accountId"`
  30. Name string `json:"name"`
  31. Type m.DsType `json:"type"`
  32. Access m.DsAccess `json:"access"`
  33. Url string `json:"url"`
  34. Password string `json:"password"`
  35. User string `json:"user"`
  36. Database string `json:"database"`
  37. BasicAuth bool `json:"basicAuth"`
  38. IsDefault bool `json:"isDefault"`
  39. }
  40. type MetricQueryResultDto struct {
  41. Data []MetricQueryResultDataDto `json:"data"`
  42. }
  43. type MetricQueryResultDataDto struct {
  44. Target string `json:"target"`
  45. DataPoints [][2]float64 `json:"datapoints"`
  46. }
  47. func GetGravatarUrl(text string) string {
  48. if text == "" {
  49. return ""
  50. }
  51. hasher := md5.New()
  52. hasher.Write([]byte(strings.ToLower(text)))
  53. return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
  54. }