models.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package dtos
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "strings"
  6. "time"
  7. m "github.com/grafana/grafana/pkg/models"
  8. )
  9. type LoginCommand struct {
  10. User string `json:"user" binding:"Required"`
  11. Password string `json:"password" binding:"Required"`
  12. Remember bool `json:"remember"`
  13. }
  14. type CurrentUser struct {
  15. IsSignedIn bool `json:"isSignedIn"`
  16. Login string `json:"login"`
  17. Email string `json:"email"`
  18. Name string `json:"name"`
  19. LightTheme bool `json:"lightTheme"`
  20. OrgId int64 `json:"orgId"`
  21. OrgName string `json:"orgName"`
  22. OrgRole m.RoleType `json:"orgRole"`
  23. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  24. GravatarUrl string `json:"gravatarUrl"`
  25. }
  26. type DashboardMeta struct {
  27. IsStarred bool `json:"isStarred,omitempty"`
  28. IsHome bool `json:"isHome,omitempty"`
  29. IsSnapshot bool `json:"isSnapshot,omitempty"`
  30. Type string `json:"type,omitempty"`
  31. CanSave bool `json:"canSave"`
  32. Slug string `json:"slug"`
  33. Expires time.Time `json:"expires"`
  34. Created time.Time `json:"created"`
  35. }
  36. type DashboardFullWithMeta struct {
  37. Meta DashboardMeta `json:"meta"`
  38. Dashboard map[string]interface{} `json:"dashboard"`
  39. }
  40. type DataSource struct {
  41. Id int64 `json:"id"`
  42. OrgId int64 `json:"orgId"`
  43. Name string `json:"name"`
  44. Type string `json:"type"`
  45. Access m.DsAccess `json:"access"`
  46. Url string `json:"url"`
  47. Password string `json:"password"`
  48. User string `json:"user"`
  49. Database string `json:"database"`
  50. BasicAuth bool `json:"basicAuth"`
  51. BasicAuthUser string `json:"basicAuthUser"`
  52. BasicAuthPassword string `json:"basicAuthPassword"`
  53. IsDefault bool `json:"isDefault"`
  54. JsonData map[string]interface{} `json:"jsonData"`
  55. }
  56. type MetricQueryResultDto struct {
  57. Data []MetricQueryResultDataDto `json:"data"`
  58. }
  59. type MetricQueryResultDataDto struct {
  60. Target string `json:"target"`
  61. DataPoints [][2]float64 `json:"datapoints"`
  62. }
  63. type UserStars struct {
  64. DashboardIds map[string]bool `json:"dashboardIds"`
  65. }
  66. func GetGravatarUrl(text string) string {
  67. if text == "" {
  68. return ""
  69. }
  70. hasher := md5.New()
  71. hasher.Write([]byte(strings.ToLower(text)))
  72. return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
  73. }