models.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. OrgRole m.RoleType `json:"orgRole"`
  21. OrgName string `json:"orgName"`
  22. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  23. GravatarUrl string `json:"gravatarUrl"`
  24. }
  25. type DashboardMeta struct {
  26. IsStarred bool `json:"isStarred"`
  27. IsHome bool `json:"isHome"`
  28. IsSnapshot bool `json:"isSnapshot"`
  29. Slug string `json:"slug"`
  30. Expires time.Time `json:"expires"`
  31. Created time.Time `json:"created"`
  32. }
  33. type Dashboard struct {
  34. Meta DashboardMeta `json:"meta"`
  35. Model map[string]interface{} `json:"model"`
  36. }
  37. type DataSource struct {
  38. Id int64 `json:"id"`
  39. OrgId int64 `json:"orgId"`
  40. Name string `json:"name"`
  41. Type string `json:"type"`
  42. Access m.DsAccess `json:"access"`
  43. Url string `json:"url"`
  44. Password string `json:"password"`
  45. User string `json:"user"`
  46. Database string `json:"database"`
  47. BasicAuth bool `json:"basicAuth"`
  48. BasicAuthUser string `json:"basicAuthUser"`
  49. BasicAuthPassword string `json:"basicAuthPassword"`
  50. IsDefault bool `json:"isDefault"`
  51. JsonData map[string]interface{} `json:"jsonData"`
  52. }
  53. type MetricQueryResultDto struct {
  54. Data []MetricQueryResultDataDto `json:"data"`
  55. }
  56. type MetricQueryResultDataDto struct {
  57. Target string `json:"target"`
  58. DataPoints [][2]float64 `json:"datapoints"`
  59. }
  60. type UserStars struct {
  61. DashboardIds map[string]bool `json:"dashboardIds"`
  62. }
  63. func GetGravatarUrl(text string) string {
  64. if text == "" {
  65. return ""
  66. }
  67. hasher := md5.New()
  68. hasher.Write([]byte(strings.ToLower(text)))
  69. return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
  70. }