Skip to content

Commit

Permalink
规范 struct data返回首字母小写
Browse files Browse the repository at this point in the history
实例修改type、envType不生效bug fix
  • Loading branch information
liuxinwang committed Sep 17, 2023
1 parent e8dd709 commit 06bd100
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 64 deletions.
12 changes: 6 additions & 6 deletions model/InspDetail.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

type InspDetail struct {
ID uint `gorm:"primaryKey;comment:主键ID"`
InspId string `gorm:"type:varchar(50);not null;comment:巡检ID"`
Metric string `gorm:"type:varchar(50);not null;comment:指标Key"`
Result datatypes.JSON `gorm:"type:json;not null;comment:结果"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间"`
ID uint `gorm:"primaryKey;comment:主键ID" json:"id"`
InspId string `gorm:"type:varchar(50);not null;comment:巡检ID" json:"inspId"`
Metric string `gorm:"type:varchar(50);not null;comment:指标Key" json:"metric"`
Result datatypes.JSON `gorm:"type:json;not null;comment:结果" json:"result"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间" json:"updatedAt"`
}
20 changes: 10 additions & 10 deletions model/Inspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package model
import "time"

type Inspection struct {
ID uint `gorm:"primaryKey;comment:主键ID"`
InspId string `gorm:"type:varchar(50);uniqueIndex:uniq_insp_id;not null;comment:巡检ID"`
InstId string `gorm:"type:varchar(20);not null;comment:实例ID"`
InstName string `gorm:"type:varchar(50);not null;comment:实例名称"`
Score int8 `gorm:"type:int;not null;default:0;comment:评分"`
Level string `gorm:"type:enum('HEALTHY', 'SUBOPTIMAL', 'RISKY', 'CRITICAL', '-');not null;default:'-';comment:健康等级"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间"`
InspDetails []InspDetail `gorm:"foreignKey:InspId;references:InspId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Scores []Score `gorm:"foreignKey:InspId;references:InspId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
ID uint `gorm:"primaryKey;comment:主键ID" json:"id"`
InspId string `gorm:"type:varchar(50);uniqueIndex:uniq_insp_id;not null;comment:巡检ID" json:"inspId"`
InstId string `gorm:"type:varchar(20);not null;comment:实例ID" json:"instId"`
InstName string `gorm:"type:varchar(50);not null;comment:实例名称" json:"instName"`
Score int8 `gorm:"type:int;not null;default:0;comment:评分" json:"score"`
Level string `gorm:"type:enum('HEALTHY', 'SUBOPTIMAL', 'RISKY', 'CRITICAL', '-');not null;default:'-';comment:健康等级" json:"level"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间" json:"updatedAt"`
InspDetails []InspDetail `gorm:"foreignKey:InspId;references:InspId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"inspDetails"`
Scores []Score `gorm:"foreignKey:InspId;references:InspId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"scores"`
}
12 changes: 6 additions & 6 deletions model/InstMetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package model
import "time"

type InstMetric struct {
ID uint `gorm:"primaryKey;comment:主键ID"`
InstId string `gorm:"type:varchar(20);uniqueIndex:uniq_inst_id_key;not null;comment:实例ID"`
Metric string `gorm:"type:varchar(50);uniqueIndex:uniq_inst_id_key;not null;comment:指标Key"`
Status string `gorm:"type:enum('Enabled', 'Disabled');not null;default:'Enabled';comment:状态;Disabled:关闭;Enabled:启用"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间"`
ID uint `gorm:"primaryKey;comment:主键ID" json:"id"`
InstId string `gorm:"type:varchar(20);uniqueIndex:uniq_inst_id_key;not null;comment:实例ID" json:"instId"`
Metric string `gorm:"type:varchar(50);uniqueIndex:uniq_inst_id_key;not null;comment:指标Key" json:"metric"`
Status string `gorm:"type:enum('Enabled', 'Disabled');not null;default:'Enabled';comment:状态;Disabled:关闭;Enabled:启用" json:"status"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间" json:"updatedAt"`
}
12 changes: 6 additions & 6 deletions model/Metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const NetworkTrafficIn string = "NETWORK_TRAFFIC_IN"
const NetworkTrafficOut string = "NETWORK_TRAFFIC_OUT"

type Metric struct {
Key string `gorm:"type:varchar(50);primaryKey;comment:指标Key"`
Name string `gorm:"type:varchar(20);not null;comment:名称"`
Unit string `gorm:"type:varchar(20);not null;comment:单位"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间"`
InstMetric []InstMetric `gorm:"foreignKey:Metric;references:Key"`
Key string `gorm:"type:varchar(50);primaryKey;comment:指标Key" json:"key"`
Name string `gorm:"type:varchar(20);not null;comment:名称" json:"name"`
Unit string `gorm:"type:varchar(20);not null;comment:单位" json:"unit"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间" json:"updatedAt"`
InstMetric []InstMetric `gorm:"foreignKey:Metric;references:Key" json:"instMetric"`
}
16 changes: 8 additions & 8 deletions model/Score.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import "time"
import "github.com/shopspring/decimal"

type Score struct {
ID uint `gorm:"primaryKey;comment:主键ID"`
InspId string `gorm:"type:varchar(50);not null;comment:巡检ID"`
Metric string `gorm:"type:varchar(50);not null;comment:指标Key"`
Value decimal.Decimal `gorm:"type:decimal(10,2);not null;comment:巡检值"`
Deduction int8 `gorm:"type:int;not null;comment:扣分"`
Message string `gorm:"type:varchar(255);not null;default:'';comment:信息"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间"`
ID uint `gorm:"primaryKey;comment:主键ID" json:"id"`
InspId string `gorm:"type:varchar(50);not null;comment:巡检ID" json:"inspId"`
Metric string `gorm:"type:varchar(50);not null;comment:指标Key" json:"metric"`
Value decimal.Decimal `gorm:"type:decimal(10,2);not null;comment:巡检值" json:"value"`
Deduction int8 `gorm:"type:int;not null;comment:扣分" json:"deduction"`
Message string `gorm:"type:varchar(255);not null;default:'';comment:信息" json:"message"`
CreatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp;comment:创建时间" json:"createdAt"`
UpdatedAt time.Time `gorm:"type:datetime;not null;default:current_timestamp on update current_timestamp;comment:修改时间" json:"updatedAt"`
}
4 changes: 2 additions & 2 deletions service/InspectionService.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func InspectionSelectByList(c *gin.Context) {
data := gin.H{"totalCount": 0, "data": &[]model.Inspection{}, "pageNo": pageNo, "pageSize": pageSize, "totalPage": 0}

// 查询条件处理
if instId, isExist := c.GetQuery("InstId"); isExist == true && strings.Trim(instId, " ") != "" {
if instId, isExist := c.GetQuery("instId"); isExist == true && strings.Trim(instId, " ") != "" {
Db = Db.Where("inst_id like ?", "%"+instId+"%")
}
if instName, isExist := c.GetQuery("InstName"); isExist == true && strings.Trim(instName, " ") != "" {
if instName, isExist := c.GetQuery("instName"); isExist == true && strings.Trim(instName, " ") != "" {
Db = Db.Where("inst_name like ?", "%"+instName+"%")
}

Expand Down
3 changes: 2 additions & 1 deletion service/InstanceService.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func InstanceUpdate(c *gin.Context) {
}
}
// 执行更新
updMap := map[string]interface{}{"name": instance.Name, "role": instance.Role, "ip": instance.Ip,
updMap := map[string]interface{}{"name": instance.Name, "type": instance.Type,
"env_type": instance.EnvType, "role": instance.Role, "ip": instance.Ip,
"port": instance.Port, "user": instance.User, "password": instance.Password}
model.Db.Model(model.Instance{}).Where("inst_id = ?", instance.InstId).Updates(updMap)
c.JSON(http.StatusOK, gin.H{"code": 1, "msg": "success", "data": "", "err": ""})
Expand Down
4 changes: 2 additions & 2 deletions tasks/InspTaskHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func InspTaskRunning(instId string) {

// 初始化巡检记录
func initInspection(instance model.Instance) (*gorm.DB, *model.Inspection) {
InspId := instance.InstId + "-" + time.Now().Format("20060102")
inspId := instance.InstId + "-" + time.Now().Format("20060102")
inspection := model.Inspection{
InspId: InspId,
InspId: inspId,
InstId: instance.InstId,
InstName: instance.Name,
}
Expand Down
46 changes: 23 additions & 23 deletions utils/Prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ type Prom struct {
}

type MysqlUserResult struct {
User string
Host string
User string `json:"user"`
Host string `json:"host"`
}

type MysqlTablesResult struct {
TableCatalog string `gorm:"column:TABLE_CATALOG"`
TableSchema string `gorm:"column:TABLE_SCHEMA"`
TableName string `gorm:"column:TABLE_NAME"`
TableType string `gorm:"column:TABLE_TYPE"`
Engine string `gorm:"column:ENGINE"`
Version int `gorm:"column:VERSION"`
RowFormat string `gorm:"column:ROW_FORMAT"`
TableRows int64 `gorm:"column:TABLE_ROWS"`
AvgRowLength int64 `gorm:"column:AVG_ROW_LENGTH"`
DataLength int64 `gorm:"column:DATA_LENGTH"`
MaxDataLength int64 `gorm:"column:MAX_DATA_LENGTH"`
IndexLength int64 `gorm:"column:INDEX_LENGTH"`
DataFree int64 `gorm:"column:DATA_FREE"`
AutoIncrement int64 `gorm:"column:AUTO_INCREMENT"`
CreateTime time.Time `gorm:"column:CREATE_TIME"`
UpdateTime time.Time `gorm:"column:UPDATE_TIME"`
CheckTime time.Time `gorm:"column:CHECK_TIME"`
TableCollation string `gorm:"column:TABLE_COLLATION"`
Checksum int64 `gorm:"column:CHECKSUM"`
CreateOptions string `gorm:"column:CREATE_OPTIONS"`
TableComment string `gorm:"column:TABLE_COMMENT"`
TableCatalog string `gorm:"column:TABLE_CATALOG" json:"tableCatalog"`
TableSchema string `gorm:"column:TABLE_SCHEMA" json:"tableSchema"`
TableName string `gorm:"column:TABLE_NAME" json:"tableName"`
TableType string `gorm:"column:TABLE_TYPE" json:"tableType"`
Engine string `gorm:"column:ENGINE" json:"engine"`
Version int `gorm:"column:VERSION" json:"version"`
RowFormat string `gorm:"column:ROW_FORMAT" json:"rowFormat"`
TableRows int64 `gorm:"column:TABLE_ROWS" json:"tableRows"`
AvgRowLength int64 `gorm:"column:AVG_ROW_LENGTH" json:"avgRowLength"`
DataLength int64 `gorm:"column:DATA_LENGTH" json:"dataLength"`
MaxDataLength int64 `gorm:"column:MAX_DATA_LENGTH" json:"maxDataLength"`
IndexLength int64 `gorm:"column:INDEX_LENGTH" json:"indexLength"`
DataFree int64 `gorm:"column:DATA_FREE" json:"dataFree"`
AutoIncrement int64 `gorm:"column:AUTO_INCREMENT" json:"autoIncrement"`
CreateTime time.Time `gorm:"column:CREATE_TIME" json:"createTime"`
UpdateTime time.Time `gorm:"column:UPDATE_TIME" json:"updateTime"`
CheckTime time.Time `gorm:"column:CHECK_TIME" json:"checkTime"`
TableCollation string `gorm:"column:TABLE_COLLATION" json:"tableCollation"`
Checksum int64 `gorm:"column:CHECKSUM" json:"checksum"`
CreateOptions string `gorm:"column:CREATE_OPTIONS" json:"createOptions"`
TableComment string `gorm:"column:TABLE_COMMENT" json:"tableComment"`
}

func PromAPI() v1.API {
Expand Down

0 comments on commit 06bd100

Please sign in to comment.