datasource.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. const (
  7. DS_GRAPHITE = "graphite"
  8. DS_INFLUXDB = "influxdb"
  9. DS_INFLUXDB_08 = "influxdb_08"
  10. DS_ES = "elasticsearch"
  11. DS_OPENTSDB = "opentsdb"
  12. DS_ACCESS_DIRECT = "direct"
  13. DS_ACCESS_PROXY = "proxy"
  14. )
  15. // Typed errors
  16. var (
  17. ErrDataSourceNotFound = errors.New("Data source not found")
  18. )
  19. type DsAccess string
  20. type DataSource struct {
  21. Id int64
  22. OrgId int64
  23. Version int
  24. Name string
  25. Type string
  26. Access DsAccess
  27. Url string
  28. Password string
  29. User string
  30. Database string
  31. BasicAuth bool
  32. BasicAuthUser string
  33. BasicAuthPassword string
  34. IsDefault bool
  35. JsonData map[string]interface{}
  36. Created time.Time
  37. Updated time.Time
  38. }
  39. // ----------------------
  40. // COMMANDS
  41. // Also acts as api DTO
  42. type AddDataSourceCommand struct {
  43. OrgId int64 `json:"-"`
  44. Name string
  45. Type string
  46. Access DsAccess
  47. Url string
  48. Password string
  49. Database string
  50. User string
  51. IsDefault bool
  52. Result *DataSource
  53. }
  54. // Also acts as api DTO
  55. type UpdateDataSourceCommand struct {
  56. Id int64 `json:"id" binding:"Required"`
  57. Name string `json:"name" binding:"Required"`
  58. Type string `json:"type" binding:"Required"`
  59. Access DsAccess `json:"access" binding:"Required"`
  60. Url string `json:"url"`
  61. Password string `json:"password"`
  62. User string `json:"user"`
  63. Database string `json:"database"`
  64. IsDefault bool `json:"isDefault"`
  65. JsonData map[string]interface{} `json:"jsonData"`
  66. OrgId int64 `json:"-"`
  67. }
  68. type DeleteDataSourceCommand struct {
  69. Id int64
  70. OrgId int64
  71. }
  72. // ---------------------
  73. // QUERIES
  74. type GetDataSourcesQuery struct {
  75. OrgId int64
  76. Result []*DataSource
  77. }
  78. type GetDataSourceByIdQuery struct {
  79. Id int64
  80. OrgId int64
  81. Result DataSource
  82. }
  83. type GetDataSourceByNameQuery struct {
  84. Name string
  85. OrgId int64
  86. Result DataSource
  87. }
  88. // ---------------------
  89. // EVENTS
  90. type DataSourceCreatedEvent struct {
  91. }