Skip to content

Commit

Permalink
refactor: datasource struct
Browse files Browse the repository at this point in the history
  • Loading branch information
710leo committed Mar 22, 2023
1 parent a897ae6 commit bad49d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cli/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Upgrade(configFile string) error {
httpJson := models.HTTP{
Timeout: cluster.Timeout,
DialTimeout: cluster.DialTimeout,
UseTLS: models.TLS{
TLS: models.TLS{
SkipTlsVerify: cluster.UseTLS,
},
MaxIdleConnsPerHost: cluster.MaxIdleConnsPerHost,
Expand Down
55 changes: 34 additions & 21 deletions models/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ import (
)

type Datasource struct {
Id int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
PluginId int64 `json:"plugin_id"`
PluginType string `json:"plugin_type"` // prometheus
PluginTypeName string `json:"plugin_type_name"` // Prometheus Like
Category string `json:"category"` // timeseries
ClusterName string `json:"cluster_name"`
Settings string `json:"-" gorm:"settings"`
SettingsJson interface{} `json:"settings" gorm:"-"`
Status string `json:"status"`
HTTP string `json:"-" gorm:"http"`
HTTPJson HTTP `json:"http" gorm:"-"`
Auth string `json:"-" gorm:"auth"`
AuthJson Auth `json:"auth" gorm:"-"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
CreatedBy string `json:"created_by"`
UpdatedBy string `json:"updated_by"`
Transport *http.Transport `json:"-" gorm:"-"`
Id int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
PluginId int64 `json:"plugin_id"`
PluginType string `json:"plugin_type"` // prometheus
PluginTypeName string `json:"plugin_type_name"` // Prometheus Like
Category string `json:"category"` // timeseries
ClusterName string `json:"cluster_name"`
Settings string `json:"-" gorm:"settings"`
SettingsJson map[string]interface{} `json:"settings" gorm:"-"`
Status string `json:"status"`
HTTP string `json:"-" gorm:"http"`
HTTPJson HTTP `json:"http" gorm:"-"`
Auth string `json:"-" gorm:"auth"`
AuthJson Auth `json:"auth" gorm:"-"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
CreatedBy string `json:"created_by"`
UpdatedBy string `json:"updated_by"`
Transport *http.Transport `json:"-" gorm:"-"`
}

type Auth struct {
Expand All @@ -44,7 +44,7 @@ type Auth struct {
type HTTP struct {
Timeout int64 `json:"timeout"`
DialTimeout int64 `json:"dial_timeout"`
UseTLS TLS `json:"tls"`
TLS TLS `json:"tls"`
MaxIdleConnsPerHost int `json:"max_idle_conns_per_host"`
Url string `json:"url"`
Headers map[string]string `json:"headers"`
Expand Down Expand Up @@ -187,6 +187,19 @@ func GetDatasourcesGetsBy(ctx *ctx.Context, typ, cate, name string, limit, offse
return lst, err
}

func GetDatasourcesGetsByTypes(ctx *ctx.Context, typs []string) (map[string]*Datasource, error) {
var lst []*Datasource
m := make(map[string]*Datasource)
err := DB(ctx).Where("plugin_type in ?", typs).Find(&lst).Error
if err == nil {
for i := 0; i < len(lst); i++ {
lst[i].DB2FE()
m[lst[i].Name] = lst[i]
}
}
return m, err
}

func (ds *Datasource) FE2DB() error {
if ds.SettingsJson != nil {
b, err := json.Marshal(ds.SettingsJson)
Expand Down

0 comments on commit bad49d2

Please sign in to comment.