refactor(errer-package): optimize package name of constant
1.optimize package name of constant
This commit is contained in:
parent
3fb78b8195
commit
b7009c351e
|
|
@ -5,7 +5,7 @@ import (
|
|||
"sort"
|
||||
"sync"
|
||||
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -18,7 +18,7 @@ var (
|
|||
type Event struct {
|
||||
ComponentID int64
|
||||
AnchorName string
|
||||
Level constant.AlertLevel
|
||||
Level constants.AlertLevel
|
||||
Message string
|
||||
StartTime int64
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ type Event struct {
|
|||
// EventManager define store and manager alert event struct
|
||||
type EventManager struct {
|
||||
mu sync.RWMutex
|
||||
events map[constant.AlertLevel][]Event
|
||||
events map[constants.AlertLevel][]Event
|
||||
}
|
||||
|
||||
// EventSet define alert event set implement sort.Interface
|
||||
|
|
@ -53,7 +53,7 @@ func (am *EventManager) AddEvent(event Event) {
|
|||
}
|
||||
|
||||
// GetEventsByLevel define get alert event by alert level
|
||||
func (am *EventManager) GetEventsByLevel(level constant.AlertLevel) []Event {
|
||||
func (am *EventManager) GetEventsByLevel(level constants.AlertLevel) []Event {
|
||||
am.mu.Lock()
|
||||
defer am.mu.Unlock()
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ func (am *EventManager) GetEventsByLevel(level constant.AlertLevel) []Event {
|
|||
}
|
||||
|
||||
// GetRangeEventsByLevel define get range alert event by alert level
|
||||
func (am *EventManager) GetRangeEventsByLevel(targetLevel constant.AlertLevel) []Event {
|
||||
func (am *EventManager) GetRangeEventsByLevel(targetLevel constants.AlertLevel) []Event {
|
||||
var targetEvents []Event
|
||||
|
||||
am.mu.Lock()
|
||||
|
|
@ -79,7 +79,7 @@ func (am *EventManager) GetRangeEventsByLevel(targetLevel constant.AlertLevel) [
|
|||
// InitAlertEventManager define new alert event manager
|
||||
func InitAlertEventManager() *EventManager {
|
||||
return &EventManager{
|
||||
events: make(map[constant.AlertLevel][]Event),
|
||||
events: make(map[constants.AlertLevel][]Event),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
package errcode
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 此处为公共的错误码, 预留 10000000 ~ 10000099 间的 100 个错误码
|
||||
var (
|
||||
Success = newError(0, "success")
|
||||
ErrServer = newError(10000000, "服务器内部错误")
|
||||
ErrParams = newError(10000001, "参数错误, 请检查")
|
||||
ErrNotFound = newError(10000002, "资源未找到")
|
||||
ErrPanic = newError(10000003, "(*^__^*)系统开小差了,请稍后重试") // 无预期的panic错误
|
||||
ErrToken = newError(10000004, "Token无效")
|
||||
ErrForbidden = newError(10000005, "未授权") // 访问一些未授权的资源时的错误
|
||||
ErrTooManyRequests = newError(10000006, "请求过多")
|
||||
ErrCoverData = newError(10000007, "ConvertDataError") // 数据转换错误
|
||||
)
|
||||
|
||||
// 各个业务模块自定义的错误码, 从 10000100 开始, 可以按照不同的业务模块划分不同的号段
|
||||
// Example:
|
||||
//var (
|
||||
// ErrOrderClosed = NewError(10000100, "订单已关闭")
|
||||
//)
|
||||
|
||||
// 用户模块相关错误码 10000100 ~ 1000199
|
||||
var (
|
||||
ErrUserInvalid = newError(10000101, "用户异常")
|
||||
ErrUserNameOccupied = newError(10000102, "用户名已被占用")
|
||||
ErrUserNotRight = newError(10000103, "用户名或密码不正确")
|
||||
)
|
||||
|
||||
// 商品模块相关错误码 10000200 ~ 1000299
|
||||
var (
|
||||
ErrCommodityNotExists = newError(10000200, "商品不存在")
|
||||
ErrCommodityStockOut = newError(10000201, "库存不足")
|
||||
)
|
||||
|
||||
// 购物车模块相关错误码 10000300 ~ 1000399
|
||||
var (
|
||||
ErrCartItemParam = newError(10000300, "购物项参数异常")
|
||||
ErrCartWrongUser = newError(10000301, "用户购物信息不匹配")
|
||||
)
|
||||
|
||||
// 订单模块相关错误码 10000500 ~ 10000599
|
||||
var (
|
||||
ErrOrderParams = newError(10000500, "订单参数异常")
|
||||
ErrOrderCanNotBeChanged = newError(10000501, "订单不可修改")
|
||||
ErrOrderUnsupportedPayScene = newError(10000502, "支付场景暂不支持")
|
||||
)
|
||||
|
||||
func (e *AppError) HttpStatusCode() int {
|
||||
switch e.Code() {
|
||||
case Success.Code():
|
||||
return http.StatusOK
|
||||
case ErrServer.Code(), ErrPanic.Code():
|
||||
return http.StatusInternalServerError
|
||||
case ErrParams.Code(), ErrUserInvalid.Code(), ErrUserNameOccupied.Code(), ErrUserNotRight.Code(),
|
||||
ErrCommodityNotExists.Code(), ErrCommodityStockOut.Code(), ErrCartItemParam.Code(), ErrOrderParams.Code():
|
||||
return http.StatusBadRequest
|
||||
case ErrNotFound.Code():
|
||||
return http.StatusNotFound
|
||||
case ErrTooManyRequests.Code():
|
||||
return http.StatusTooManyRequests
|
||||
case ErrToken.Code():
|
||||
return http.StatusUnauthorized
|
||||
case ErrForbidden.Code(), ErrCartWrongUser.Code(), ErrOrderCanNotBeChanged.Code():
|
||||
return http.StatusForbidden
|
||||
default:
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package errcode
|
||||
|
||||
import "errors"
|
||||
|
||||
// Database layer error
|
||||
var (
|
||||
// ErrUUIDChangeType define error of check uuid from value failed in uuid from change type
|
||||
ErrUUIDChangeType = errors.New("undefined uuid change type")
|
||||
|
||||
// ErrUpdateRowZero define error of update affected row zero
|
||||
ErrUpdateRowZero = errors.New("update affected rows is zero")
|
||||
|
||||
// ErrDeleteRowZero define error of delete affected row zero
|
||||
ErrDeleteRowZero = errors.New("delete affected rows is zero")
|
||||
|
||||
// ErrQueryRowZero define error of query affected row zero
|
||||
ErrQueryRowZero = errors.New("query affected rows is zero")
|
||||
|
||||
// ErrInsertRowUnexpected define error of insert affected row not reach expected number
|
||||
ErrInsertRowUnexpected = errors.New("the number of inserted data rows don't reach the expected value")
|
||||
)
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
)
|
||||
|
||||
// AnchorParamListConfig define anchor params list config struct
|
||||
|
|
@ -43,7 +43,7 @@ var baseCurrentFunc = func(archorValue float64, args ...float64) float64 {
|
|||
|
||||
// SelectAnchorCalculateFuncAndParams define select anchor func and anchor calculate value by component type 、 anchor name and component data
|
||||
func SelectAnchorCalculateFuncAndParams(componentType int, anchorName string, componentData map[string]interface{}) (func(archorValue float64, args ...float64) float64, []float64) {
|
||||
if componentType == constant.DemoType {
|
||||
if componentType == constants.DemoType {
|
||||
if anchorName == "voltage" {
|
||||
resistance := componentData["resistance"].(float64)
|
||||
return baseVoltageFunc, []float64{resistance}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Package constant define alert level constant
|
||||
package constant
|
||||
// Package constants define constant variable
|
||||
package constants
|
||||
|
||||
// AlertLevel define alert level type
|
||||
type AlertLevel int
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package constant
|
||||
// Package constants define constant variable
|
||||
package constants
|
||||
|
||||
const (
|
||||
// 母线服役属性
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Package constant define constant value
|
||||
package constant
|
||||
// Package constants define constant variable
|
||||
package constants
|
||||
|
||||
const (
|
||||
// NullableType 空类型类型
|
||||
|
|
|
|||
|
|
@ -1,22 +1,8 @@
|
|||
package constant
|
||||
// Package constants define constant variable
|
||||
package constants
|
||||
|
||||
import "errors"
|
||||
|
||||
// ErrUUIDChangeType define error of check uuid from value failed in uuid from change type
|
||||
var ErrUUIDChangeType = errors.New("undefined uuid change type")
|
||||
|
||||
// ErrUpdateRowZero define error of update affected row zero
|
||||
var ErrUpdateRowZero = errors.New("update affected rows is zero")
|
||||
|
||||
// ErrDeleteRowZero define error of delete affected row zero
|
||||
var ErrDeleteRowZero = errors.New("delete affected rows is zero")
|
||||
|
||||
// ErrQueryRowZero define error of query affected row zero
|
||||
var ErrQueryRowZero = errors.New("query affected rows is zero")
|
||||
|
||||
// ErrInsertRowUnexpected define error of insert affected row not reach expected number
|
||||
var ErrInsertRowUnexpected = errors.New("the number of inserted data rows don't reach the expected value")
|
||||
|
||||
var (
|
||||
// ErrUUIDFromCheckT1 define error of check uuid from value failed in uuid from change type
|
||||
ErrUUIDFromCheckT1 = errors.New("in uuid from change type, value of new uuid_from is equal value of old uuid_from")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Package constant define constant value
|
||||
package constant
|
||||
// Package constants define constant variable
|
||||
package constants
|
||||
|
||||
const (
|
||||
// DevelopmentLogMode define development operator environment for modelRT project
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Package constant define constant value
|
||||
package constant
|
||||
// Package constants define constant variable
|
||||
package constants
|
||||
|
||||
const (
|
||||
// LogTimeFormate define time format for log file name
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
package constant
|
||||
// Package constants define constant variable
|
||||
package constants
|
||||
|
||||
import "github.com/gofrs/uuid"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
"modelRT/network"
|
||||
"modelRT/orm"
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ func CreateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo netwo
|
|||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check insert component slice", constant.ErrInsertRowUnexpected)
|
||||
err = fmt.Errorf("%w:please check insert component slice", errcode.ErrInsertRowUnexpected)
|
||||
}
|
||||
return -1, fmt.Errorf("insert component info failed:%w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
"modelRT/model"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
|
@ -28,7 +28,7 @@ func CreateModelIntoDB(ctx context.Context, tx *gorm.DB, componentID int64, comp
|
|||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check insert model params", constant.ErrInsertRowUnexpected)
|
||||
err = fmt.Errorf("%w:please check insert model params", errcode.ErrInsertRowUnexpected)
|
||||
}
|
||||
return fmt.Errorf("insert component model params into table %s failed:%w", modelStruct.ReturnTableName(), err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
"modelRT/network"
|
||||
"modelRT/orm"
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ func CreateTopologicIntoDB(ctx context.Context, tx *gorm.DB, pageID int64, topol
|
|||
if result.Error != nil || result.RowsAffected != int64(len(topologicSlice)) {
|
||||
err := result.Error
|
||||
if result.RowsAffected != int64(len(topologicSlice)) {
|
||||
err = fmt.Errorf("%w:please check insert topologic slice", constant.ErrInsertRowUnexpected)
|
||||
err = fmt.Errorf("%w:please check insert topologic slice", errcode.ErrInsertRowUnexpected)
|
||||
}
|
||||
return fmt.Errorf("insert topologic link failed:%w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
"modelRT/network"
|
||||
"modelRT/orm"
|
||||
|
||||
|
|
@ -23,7 +23,7 @@ func DeleteTopologicIntoDB(ctx context.Context, tx *gorm.DB, pageID int64, delIn
|
|||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check delete topologic where conditions", constant.ErrDeleteRowZero)
|
||||
err = fmt.Errorf("%w:please check delete topologic where conditions", errcode.ErrDeleteRowZero)
|
||||
}
|
||||
return fmt.Errorf("delete topologic link failed:%w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/diagram"
|
||||
"modelRT/logger"
|
||||
"modelRT/orm"
|
||||
|
|
@ -24,9 +24,9 @@ func QueryTopologic(ctx context.Context, tx *gorm.DB) ([]orm.Topologic, error) {
|
|||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Raw(sql.RecursiveSQL, constant.UUIDNilStr).Scan(&topologics)
|
||||
result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Raw(sql.RecursiveSQL, constants.UUIDNilStr).Scan(&topologics)
|
||||
if result.Error != nil {
|
||||
logger.Error(ctx, "query circuit diagram topologic info by start node uuid failed", "start_node_uuid", constant.UUIDNilStr, "error", result.Error)
|
||||
logger.Error(ctx, "query circuit diagram topologic info by start node uuid failed", "start_node_uuid", constants.UUIDNilStr, "error", result.Error)
|
||||
return nil, result.Error
|
||||
}
|
||||
return topologics, nil
|
||||
|
|
@ -52,7 +52,7 @@ func QueryTopologicFromDB(ctx context.Context, tx *gorm.DB, componentTypeMap map
|
|||
func InitCircuitDiagramTopologic(topologicNodes []orm.Topologic, componentTypeMap map[uuid.UUID]int) error {
|
||||
var rootVertex *diagram.MultiBranchTreeNode
|
||||
for _, node := range topologicNodes {
|
||||
if node.UUIDFrom == constant.UUIDNil {
|
||||
if node.UUIDFrom == constants.UUIDNil {
|
||||
// rootVertex = node.UUIDTo
|
||||
var componentType int
|
||||
componentType, ok := componentTypeMap[node.UUIDFrom]
|
||||
|
|
@ -69,7 +69,7 @@ func InitCircuitDiagramTopologic(topologicNodes []orm.Topologic, componentTypeMa
|
|||
}
|
||||
|
||||
for _, node := range topologicNodes {
|
||||
if node.UUIDFrom == constant.UUIDNil {
|
||||
if node.UUIDFrom == constants.UUIDNil {
|
||||
var componentType int
|
||||
componentType, ok := componentTypeMap[node.UUIDTo]
|
||||
if !ok {
|
||||
|
|
@ -110,7 +110,7 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
|||
for _, topo := range topologics {
|
||||
if _, exists := nodeMap[topo.UUIDFrom]; !exists {
|
||||
// skip special uuid
|
||||
if topo.UUIDTo != constant.UUIDNil {
|
||||
if topo.UUIDTo != constants.UUIDNil {
|
||||
var ok bool
|
||||
componentType, ok := componentTypeMap[topo.UUIDFrom]
|
||||
if !ok {
|
||||
|
|
@ -127,7 +127,7 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
|||
|
||||
if _, exists := nodeMap[topo.UUIDTo]; !exists {
|
||||
// skip special uuid
|
||||
if topo.UUIDTo != constant.UUIDNil {
|
||||
if topo.UUIDTo != constants.UUIDNil {
|
||||
var ok bool
|
||||
componentType, ok := componentTypeMap[topo.UUIDTo]
|
||||
if !ok {
|
||||
|
|
@ -145,19 +145,19 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
|||
|
||||
for _, topo := range topologics {
|
||||
var parent *diagram.MultiBranchTreeNode
|
||||
if topo.UUIDFrom == constant.UUIDNil {
|
||||
if topo.UUIDFrom == constants.UUIDNil {
|
||||
var componentType int
|
||||
parent = &diagram.MultiBranchTreeNode{
|
||||
ID: constant.UUIDNil,
|
||||
ID: constants.UUIDNil,
|
||||
NodeComponentType: componentType,
|
||||
}
|
||||
nodeMap[constant.UUIDNil] = parent
|
||||
nodeMap[constants.UUIDNil] = parent
|
||||
} else {
|
||||
parent = nodeMap[topo.UUIDFrom]
|
||||
}
|
||||
|
||||
var child *diagram.MultiBranchTreeNode
|
||||
if topo.UUIDTo == constant.UUIDNil {
|
||||
if topo.UUIDTo == constants.UUIDNil {
|
||||
var componentType int
|
||||
child = &diagram.MultiBranchTreeNode{
|
||||
ID: topo.UUIDTo,
|
||||
|
|
@ -171,7 +171,7 @@ func BuildMultiBranchTree(topologics []orm.Topologic, componentTypeMap map[uuid.
|
|||
}
|
||||
|
||||
// return root vertex
|
||||
root, exists := nodeMap[constant.UUIDNil]
|
||||
root, exists := nodeMap[constants.UUIDNil]
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("root node not found")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
"modelRT/network"
|
||||
"modelRT/orm"
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ func UpdateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo netwo
|
|||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check update component conditions", constant.ErrUpdateRowZero)
|
||||
err = fmt.Errorf("%w:please check update component conditions", errcode.ErrUpdateRowZero)
|
||||
}
|
||||
return -1, fmt.Errorf("query component info failed:%w", err)
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ func UpdateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo netwo
|
|||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check update component conditions", constant.ErrUpdateRowZero)
|
||||
err = fmt.Errorf("%w:please check update component conditions", errcode.ErrUpdateRowZero)
|
||||
}
|
||||
return -1, fmt.Errorf("update component info failed:%w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
"modelRT/model"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
|
@ -33,7 +33,7 @@ func UpdateModelIntoDB(ctx context.Context, tx *gorm.DB, componentID int64, comp
|
|||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check where conditions", constant.ErrUpdateRowZero)
|
||||
err = fmt.Errorf("%w:please check where conditions", errcode.ErrUpdateRowZero)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/network"
|
||||
"modelRT/orm"
|
||||
|
||||
|
|
@ -21,9 +22,9 @@ func UpdateTopologicIntoDB(ctx context.Context, tx *gorm.DB, pageID int64, chang
|
|||
defer cancel()
|
||||
|
||||
switch changeInfo.ChangeType {
|
||||
case constant.UUIDFromChangeType:
|
||||
case constants.UUIDFromChangeType:
|
||||
result = tx.WithContext(cancelCtx).Model(&orm.Topologic{}).Where("page_id = ? and uuid_from = ? and uuid_to = ?", pageID, changeInfo.OldUUIDFrom, changeInfo.OldUUIDTo).Updates(orm.Topologic{UUIDFrom: changeInfo.NewUUIDFrom})
|
||||
case constant.UUIDToChangeType:
|
||||
case constants.UUIDToChangeType:
|
||||
var delTopologic orm.Topologic
|
||||
result = tx.WithContext(cancelCtx).Model(&orm.Topologic{}).Where("page_id = ? and uuid_to = ?", pageID, changeInfo.NewUUIDTo).Find(&delTopologic)
|
||||
|
||||
|
|
@ -38,14 +39,14 @@ func UpdateTopologicIntoDB(ctx context.Context, tx *gorm.DB, pageID int64, chang
|
|||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check delete topologic where conditions", constant.ErrDeleteRowZero)
|
||||
err = fmt.Errorf("%w:please check delete topologic where conditions", errcode.ErrDeleteRowZero)
|
||||
}
|
||||
return fmt.Errorf("del old topologic link by new_uuid_to failed:%w", err)
|
||||
}
|
||||
}
|
||||
|
||||
result = tx.WithContext(cancelCtx).Model(&orm.Topologic{}).Where("page_id = ? and uuid_from = ? and uuid_to = ?", pageID, changeInfo.OldUUIDFrom, changeInfo.OldUUIDTo).Updates(&orm.Topologic{UUIDTo: changeInfo.NewUUIDTo})
|
||||
case constant.UUIDAddChangeType:
|
||||
case constants.UUIDAddChangeType:
|
||||
topologic := orm.Topologic{
|
||||
Flag: changeInfo.Flag,
|
||||
UUIDFrom: changeInfo.NewUUIDFrom,
|
||||
|
|
@ -60,7 +61,7 @@ func UpdateTopologicIntoDB(ctx context.Context, tx *gorm.DB, pageID int64, chang
|
|||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check update topologic where conditions", constant.ErrUpdateRowZero)
|
||||
err = fmt.Errorf("%w:please check update topologic where conditions", errcode.ErrUpdateRowZero)
|
||||
}
|
||||
return fmt.Errorf("insert or update topologic link failed:%w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/network"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
|
|
@ -148,7 +148,7 @@ func (g *Graph) PrintGraph() {
|
|||
|
||||
// UpdateEdge update edge link info between two verticeLinks
|
||||
func (g *Graph) UpdateEdge(changeInfo network.TopologicUUIDChangeInfos) error {
|
||||
if changeInfo.ChangeType == constant.UUIDFromChangeType || changeInfo.ChangeType == constant.UUIDToChangeType {
|
||||
if changeInfo.ChangeType == constants.UUIDFromChangeType || changeInfo.ChangeType == constants.UUIDToChangeType {
|
||||
g.DelEdge(changeInfo.OldUUIDFrom, changeInfo.OldUUIDTo)
|
||||
g.AddEdge(changeInfo.NewUUIDFrom, changeInfo.NewUUIDTo)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package constant
|
||||
package constants
|
||||
|
||||
import "errors"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package constant
|
||||
package constants
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"modelRT/distributedlock/constant"
|
||||
constants "modelRT/distributedlock/constant"
|
||||
luascript "modelRT/distributedlock/luascript"
|
||||
"modelRT/logger"
|
||||
|
||||
|
|
@ -49,13 +49,13 @@ func (rl *redissionLocker) Lock(ctx context.Context, timeout ...time.Duration) e
|
|||
if rl.refreshExitChan == nil {
|
||||
rl.refreshExitChan = make(chan struct{})
|
||||
}
|
||||
result := rl.tryLock(ctx).(*constant.RedisResult)
|
||||
if result.Code == constant.UnknownInternalError {
|
||||
result := rl.tryLock(ctx).(*constants.RedisResult)
|
||||
if result.Code == constants.UnknownInternalError {
|
||||
logger.Error(ctx, result.OutputResultMessage())
|
||||
return fmt.Errorf("get lock failed:%w", result)
|
||||
}
|
||||
|
||||
if (result.Code == constant.LockSuccess) && rl.needRefresh {
|
||||
if (result.Code == constants.LockSuccess) && rl.needRefresh {
|
||||
rl.refreshOnce.Do(func() {
|
||||
// async refresh lock timeout unitl receive exit singal
|
||||
go rl.refreshLockTimeout(ctx)
|
||||
|
|
@ -80,13 +80,13 @@ func (rl *redissionLocker) Lock(ctx context.Context, timeout ...time.Duration) e
|
|||
return err
|
||||
}
|
||||
|
||||
resultErr := rl.tryLock(ctx).(*constant.RedisResult)
|
||||
if (resultErr.Code == constant.LockFailure) || (resultErr.Code == constant.UnknownInternalError) {
|
||||
resultErr := rl.tryLock(ctx).(*constants.RedisResult)
|
||||
if (resultErr.Code == constants.LockFailure) || (resultErr.Code == constants.UnknownInternalError) {
|
||||
logger.Info(ctx, resultErr.OutputResultMessage())
|
||||
continue
|
||||
}
|
||||
|
||||
if resultErr.Code == constant.LockSuccess {
|
||||
if resultErr.Code == constants.LockSuccess {
|
||||
logger.Info(ctx, resultErr.OutputResultMessage())
|
||||
return nil
|
||||
}
|
||||
|
|
@ -142,12 +142,12 @@ func (rl *redissionLocker) refreshLockTimeout(ctx context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if constant.RedisCode(val) == constant.RefreshLockFailure {
|
||||
if constants.RedisCode(val) == constants.RefreshLockFailure {
|
||||
logger.Error(ctx, "lock refreash failed,can not find the lock by key and token", "token", rl.Token, "key", rl.Key)
|
||||
break
|
||||
}
|
||||
|
||||
if constant.RedisCode(val) == constant.RefreshLockSuccess {
|
||||
if constants.RedisCode(val) == constants.RefreshLockSuccess {
|
||||
logger.Info(ctx, "lock refresh success by key and token", "token", rl.Token, "key", rl.Key)
|
||||
}
|
||||
timer.Reset(lockTime)
|
||||
|
|
@ -183,13 +183,13 @@ ARGV[1]:锁的过期时间(lockLeaseTime),单位为秒。
|
|||
ARGV[2]:当前客户端的唯一标识(token),用于区分不同的客户端。
|
||||
*/
|
||||
func (rl *redissionLocker) tryLock(ctx context.Context) error {
|
||||
lockType := constant.LockType
|
||||
lockType := constants.LockType
|
||||
res := rl.client.Eval(ctx, luascript.LockScript, []string{rl.Key}, rl.lockLeaseTime, rl.Token)
|
||||
val, err := res.Int()
|
||||
if err != redis.Nil && err != nil {
|
||||
return constant.NewRedisResult(constant.UnknownInternalError, lockType, err.Error())
|
||||
return constants.NewRedisResult(constants.UnknownInternalError, lockType, err.Error())
|
||||
}
|
||||
return constant.NewRedisResult(constant.RedisCode(val), lockType, "")
|
||||
return constants.NewRedisResult(constants.RedisCode(val), lockType, "")
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -203,10 +203,10 @@ func (rl *redissionLocker) UnLock(ctx context.Context) error {
|
|||
val, err := res.Int()
|
||||
if err != redis.Nil && err != nil {
|
||||
logger.Info(ctx, "unlock lock failed", zap.String("token", rl.Token), zap.String("key", rl.Key), zap.Error(err))
|
||||
return fmt.Errorf("unlock lock failed:%w", constant.NewRedisResult(constant.UnknownInternalError, constant.UnLockType, err.Error()))
|
||||
return fmt.Errorf("unlock lock failed:%w", constants.NewRedisResult(constants.UnknownInternalError, constants.UnLockType, err.Error()))
|
||||
}
|
||||
|
||||
if constant.RedisCode(val) == constant.UnLockSuccess {
|
||||
if constants.RedisCode(val) == constants.UnLockSuccess {
|
||||
if rl.needRefresh {
|
||||
rl.cancelRefreshLockTime()
|
||||
}
|
||||
|
|
@ -215,9 +215,9 @@ func (rl *redissionLocker) UnLock(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if constant.RedisCode(val) == constant.UnLocakFailureWithLockOccupancy {
|
||||
if constants.RedisCode(val) == constants.UnLocakFailureWithLockOccupancy {
|
||||
logger.Info(ctx, "unlock lock failed", zap.String("token", rl.Token), zap.String("key", rl.Key))
|
||||
return fmt.Errorf("unlock lock failed:%w", constant.NewRedisResult(constant.UnLocakFailureWithLockOccupancy, constant.UnLockType, ""))
|
||||
return fmt.Errorf("unlock lock failed:%w", constants.NewRedisResult(constants.UnLocakFailureWithLockOccupancy, constants.UnLockType, ""))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"modelRT/distributedlock/constant"
|
||||
constants "modelRT/distributedlock/constant"
|
||||
"modelRT/distributedlock/luascript"
|
||||
"modelRT/logger"
|
||||
|
||||
|
|
@ -24,13 +24,13 @@ type RedissionRWLocker struct {
|
|||
}
|
||||
|
||||
func (rl *RedissionRWLocker) RLock(ctx context.Context, timeout ...time.Duration) error {
|
||||
result := rl.tryRLock(ctx).(*constant.RedisResult)
|
||||
if result.Code == constant.UnknownInternalError {
|
||||
result := rl.tryRLock(ctx).(*constants.RedisResult)
|
||||
if result.Code == constants.UnknownInternalError {
|
||||
logger.Error(ctx, result.OutputResultMessage())
|
||||
return fmt.Errorf("get read lock failed:%w", result)
|
||||
}
|
||||
|
||||
if result.Code == constant.LockSuccess {
|
||||
if result.Code == constants.LockSuccess {
|
||||
if rl.needRefresh {
|
||||
rl.refreshOnce.Do(func() {
|
||||
if rl.refreshExitChan == nil {
|
||||
|
|
@ -64,13 +64,13 @@ func (rl *RedissionRWLocker) RLock(ctx context.Context, timeout ...time.Duration
|
|||
return err
|
||||
}
|
||||
|
||||
result := rl.tryRLock(ctx).(*constant.RedisResult)
|
||||
if (result.Code == constant.RLockFailureWithWLockOccupancy) || (result.Code == constant.UnknownInternalError) {
|
||||
result := rl.tryRLock(ctx).(*constants.RedisResult)
|
||||
if (result.Code == constants.RLockFailureWithWLockOccupancy) || (result.Code == constants.UnknownInternalError) {
|
||||
logger.Info(ctx, result.OutputResultMessage())
|
||||
continue
|
||||
}
|
||||
|
||||
if result.Code == constant.LockSuccess {
|
||||
if result.Code == constants.LockSuccess {
|
||||
logger.Info(ctx, result.OutputResultMessage())
|
||||
rl.closeSub(ctx, sub, rl.subExitChan)
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ func (rl *RedissionRWLocker) RLock(ctx context.Context, timeout ...time.Duration
|
|||
logger.Info(ctx, "the waiting time for obtaining the read lock operation has timed out")
|
||||
rl.closeSub(ctx, sub, rl.subExitChan)
|
||||
// after acquire lock timeout,notice the sub channel to close
|
||||
return constant.AcquireTimeoutErr
|
||||
return constants.AcquireTimeoutErr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -98,14 +98,14 @@ func (rl *RedissionRWLocker) RLock(ctx context.Context, timeout ...time.Duration
|
|||
}
|
||||
|
||||
func (rl *RedissionRWLocker) tryRLock(ctx context.Context) error {
|
||||
lockType := constant.LockType
|
||||
lockType := constants.LockType
|
||||
|
||||
res := rl.client.Eval(ctx, luascript.RLockScript, []string{rl.Key, rl.RWTokenTimeoutPrefix}, rl.lockLeaseTime, rl.Token)
|
||||
val, err := res.Int()
|
||||
if err != redis.Nil && err != nil {
|
||||
return constant.NewRedisResult(constant.UnknownInternalError, lockType, err.Error())
|
||||
return constants.NewRedisResult(constants.UnknownInternalError, lockType, err.Error())
|
||||
}
|
||||
return constant.NewRedisResult(constant.RedisCode(val), lockType, "")
|
||||
return constants.NewRedisResult(constants.RedisCode(val), lockType, "")
|
||||
}
|
||||
|
||||
func (rl *RedissionRWLocker) refreshLockTimeout(ctx context.Context) {
|
||||
|
|
@ -126,12 +126,12 @@ func (rl *RedissionRWLocker) refreshLockTimeout(ctx context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if constant.RedisCode(val) == constant.RefreshLockFailure {
|
||||
if constants.RedisCode(val) == constants.RefreshLockFailure {
|
||||
logger.Error(ctx, "lock refreash failed,can not find the read lock by key and token", "rwTokenPrefix", rl.RWTokenTimeoutPrefix, "token", rl.Token, "key", rl.Key)
|
||||
return
|
||||
}
|
||||
|
||||
if constant.RedisCode(val) == constant.RefreshLockSuccess {
|
||||
if constants.RedisCode(val) == constants.RefreshLockSuccess {
|
||||
logger.Info(ctx, "lock refresh success by key and token", "token", rl.Token, "key", rl.Key)
|
||||
}
|
||||
timer.Reset(lockTime)
|
||||
|
|
@ -147,11 +147,11 @@ func (rl *RedissionRWLocker) UnRLock(ctx context.Context) error {
|
|||
val, err := res.Int()
|
||||
if err != redis.Nil && err != nil {
|
||||
logger.Info(ctx, "unlock read lock failed", "token", rl.Token, "key", rl.Key, "error", err)
|
||||
return fmt.Errorf("unlock read lock failed:%w", constant.NewRedisResult(constant.UnknownInternalError, constant.UnRLockType, err.Error()))
|
||||
return fmt.Errorf("unlock read lock failed:%w", constants.NewRedisResult(constants.UnknownInternalError, constants.UnRLockType, err.Error()))
|
||||
}
|
||||
|
||||
if (constant.RedisCode(val) == constant.UnLockSuccess) || (constant.RedisCode(val) == constant.UnRLockSuccess) {
|
||||
if rl.needRefresh && (constant.RedisCode(val) == constant.UnLockSuccess) {
|
||||
if (constants.RedisCode(val) == constants.UnLockSuccess) || (constants.RedisCode(val) == constants.UnRLockSuccess) {
|
||||
if rl.needRefresh && (constants.RedisCode(val) == constants.UnLockSuccess) {
|
||||
rl.cancelRefreshLockTime()
|
||||
}
|
||||
|
||||
|
|
@ -159,21 +159,21 @@ func (rl *RedissionRWLocker) UnRLock(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if constant.RedisCode(val) == constant.UnRLockFailureWithWLockOccupancy {
|
||||
if constants.RedisCode(val) == constants.UnRLockFailureWithWLockOccupancy {
|
||||
logger.Info(ctx, "unlock read lock failed", "token", rl.Token, "key", rl.Key)
|
||||
return fmt.Errorf("unlock read lock failed:%w", constant.NewRedisResult(constant.UnRLockFailureWithWLockOccupancy, constant.UnRLockType, ""))
|
||||
return fmt.Errorf("unlock read lock failed:%w", constants.NewRedisResult(constants.UnRLockFailureWithWLockOccupancy, constants.UnRLockType, ""))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rl *RedissionRWLocker) WLock(ctx context.Context, timeout ...time.Duration) error {
|
||||
result := rl.tryWLock(ctx).(*constant.RedisResult)
|
||||
if result.Code == constant.UnknownInternalError {
|
||||
result := rl.tryWLock(ctx).(*constants.RedisResult)
|
||||
if result.Code == constants.UnknownInternalError {
|
||||
logger.Error(ctx, result.OutputResultMessage())
|
||||
return fmt.Errorf("get write lock failed:%w", result)
|
||||
}
|
||||
|
||||
if result.Code == constant.LockSuccess {
|
||||
if result.Code == constants.LockSuccess {
|
||||
if rl.needRefresh {
|
||||
rl.refreshOnce.Do(func() {
|
||||
if rl.refreshExitChan == nil {
|
||||
|
|
@ -207,13 +207,13 @@ func (rl *RedissionRWLocker) WLock(ctx context.Context, timeout ...time.Duration
|
|||
return err
|
||||
}
|
||||
|
||||
result := rl.tryWLock(ctx).(*constant.RedisResult)
|
||||
if (result.Code == constant.UnknownInternalError) || (result.Code == constant.WLockFailureWithRLockOccupancy) || (result.Code == constant.WLockFailureWithWLockOccupancy) || (result.Code == constant.WLockFailureWithNotFirstPriority) {
|
||||
result := rl.tryWLock(ctx).(*constants.RedisResult)
|
||||
if (result.Code == constants.UnknownInternalError) || (result.Code == constants.WLockFailureWithRLockOccupancy) || (result.Code == constants.WLockFailureWithWLockOccupancy) || (result.Code == constants.WLockFailureWithNotFirstPriority) {
|
||||
logger.Info(ctx, result.OutputResultMessage())
|
||||
continue
|
||||
}
|
||||
|
||||
if result.Code == constant.LockSuccess {
|
||||
if result.Code == constants.LockSuccess {
|
||||
logger.Info(ctx, result.OutputResultMessage())
|
||||
rl.closeSub(ctx, sub, rl.subExitChan)
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ func (rl *RedissionRWLocker) WLock(ctx context.Context, timeout ...time.Duration
|
|||
logger.Info(ctx, "the waiting time for obtaining the write lock operation has timed out")
|
||||
rl.closeSub(ctx, sub, rl.subExitChan)
|
||||
// after acquire lock timeout,notice the sub channel to close
|
||||
return constant.AcquireTimeoutErr
|
||||
return constants.AcquireTimeoutErr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -241,14 +241,14 @@ func (rl *RedissionRWLocker) WLock(ctx context.Context, timeout ...time.Duration
|
|||
}
|
||||
|
||||
func (rl *RedissionRWLocker) tryWLock(ctx context.Context) error {
|
||||
lockType := constant.LockType
|
||||
lockType := constants.LockType
|
||||
|
||||
res := rl.client.Eval(ctx, luascript.WLockScript, []string{rl.Key, rl.RWTokenTimeoutPrefix}, rl.lockLeaseTime, rl.Token)
|
||||
val, err := res.Int()
|
||||
if err != redis.Nil && err != nil {
|
||||
return constant.NewRedisResult(constant.UnknownInternalError, lockType, err.Error())
|
||||
return constants.NewRedisResult(constants.UnknownInternalError, lockType, err.Error())
|
||||
}
|
||||
return constant.NewRedisResult(constant.RedisCode(val), lockType, "")
|
||||
return constants.NewRedisResult(constants.RedisCode(val), lockType, "")
|
||||
}
|
||||
|
||||
func (rl *RedissionRWLocker) UnWLock(ctx context.Context) error {
|
||||
|
|
@ -256,20 +256,20 @@ func (rl *RedissionRWLocker) UnWLock(ctx context.Context) error {
|
|||
val, err := res.Int()
|
||||
if err != redis.Nil && err != nil {
|
||||
logger.Error(ctx, "unlock write lock failed", "token", rl.Token, "key", rl.Key, "error", err)
|
||||
return fmt.Errorf("unlock write lock failed:%w", constant.NewRedisResult(constant.UnknownInternalError, constant.UnWLockType, err.Error()))
|
||||
return fmt.Errorf("unlock write lock failed:%w", constants.NewRedisResult(constants.UnknownInternalError, constants.UnWLockType, err.Error()))
|
||||
}
|
||||
|
||||
if (constant.RedisCode(val) == constant.UnLockSuccess) || constant.RedisCode(val) == constant.UnWLockSuccess {
|
||||
if rl.needRefresh && (constant.RedisCode(val) == constant.UnLockSuccess) {
|
||||
if (constants.RedisCode(val) == constants.UnLockSuccess) || constants.RedisCode(val) == constants.UnWLockSuccess {
|
||||
if rl.needRefresh && (constants.RedisCode(val) == constants.UnLockSuccess) {
|
||||
rl.cancelRefreshLockTime()
|
||||
}
|
||||
logger.Info(ctx, "unlock write lock success", "token", rl.Token, "key", rl.Key)
|
||||
return nil
|
||||
}
|
||||
|
||||
if (constant.RedisCode(val) == constant.UnWLockFailureWithRLockOccupancy) || (constant.RedisCode(val) == constant.UnWLockFailureWithWLockOccupancy) {
|
||||
if (constants.RedisCode(val) == constants.UnWLockFailureWithRLockOccupancy) || (constants.RedisCode(val) == constants.UnWLockFailureWithWLockOccupancy) {
|
||||
logger.Info(ctx, "unlock write lock failed", "token", rl.Token, "key", rl.Key)
|
||||
return fmt.Errorf("unlock write lock failed:%w", constant.NewRedisResult(constant.RedisCode(val), constant.UnWLockType, ""))
|
||||
return fmt.Errorf("unlock write lock failed:%w", constants.NewRedisResult(constants.RedisCode(val), constants.UnWLockType, ""))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strconv"
|
||||
|
||||
"modelRT/alert"
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/logger"
|
||||
"modelRT/network"
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
// QueryAlertEventHandler define query alert event process API
|
||||
func QueryAlertEventHandler(c *gin.Context) {
|
||||
var targetLevel constant.AlertLevel
|
||||
var targetLevel constants.AlertLevel
|
||||
|
||||
alertManger := alert.GetAlertMangerInstance()
|
||||
levelStr := c.Query("level")
|
||||
|
|
@ -29,7 +29,7 @@ func QueryAlertEventHandler(c *gin.Context) {
|
|||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
targetLevel = constant.AlertLevel(level)
|
||||
targetLevel = constants.AlertLevel(level)
|
||||
events := alertManger.GetRangeEventsByLevel(targetLevel)
|
||||
|
||||
resp := network.SuccessResponse{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/database"
|
||||
"modelRT/diagram"
|
||||
"modelRT/logger"
|
||||
|
|
@ -54,7 +55,7 @@ func ComponentAnchorReplaceHandler(c *gin.Context) {
|
|||
}
|
||||
|
||||
if result.RowsAffected == 0 {
|
||||
err := fmt.Errorf("query component detail info by uuid failed:%w", constant.ErrQueryRowZero)
|
||||
err := fmt.Errorf("query component detail info by uuid failed:%w", errcode.ErrQueryRowZero)
|
||||
logger.Error(c, "query component detail info from table is empty", "table_name", "component")
|
||||
|
||||
resp := network.FailureResponse{
|
||||
|
|
@ -82,7 +83,7 @@ func ComponentAnchorReplaceHandler(c *gin.Context) {
|
|||
}
|
||||
|
||||
if unmarshalMap == nil {
|
||||
err := fmt.Errorf("query model detail info by uuid failed:%w", constant.ErrQueryRowZero)
|
||||
err := fmt.Errorf("query model detail info by uuid failed:%w", errcode.ErrQueryRowZero)
|
||||
logger.Error(c, "query model detail info from table is empty", "table_name", tableName)
|
||||
|
||||
resp := network.FailureResponse{
|
||||
|
|
@ -94,7 +95,7 @@ func ComponentAnchorReplaceHandler(c *gin.Context) {
|
|||
}
|
||||
|
||||
componentType := unmarshalMap["component_type"].(int)
|
||||
if componentType != constant.DemoType {
|
||||
if componentType != constants.DemoType {
|
||||
logger.Error(c, "can not process real time data of component type not equal DemoType", "component_id", componentInfo.ID)
|
||||
}
|
||||
diagram.UpdateAnchorValue(componentInfo.ID, anchorName)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
"modelRT/database"
|
||||
"modelRT/diagram"
|
||||
"modelRT/logger"
|
||||
|
|
@ -155,7 +155,7 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check uuid conditions", constant.ErrDeleteRowZero)
|
||||
err = fmt.Errorf("%w:please check uuid conditions", errcode.ErrDeleteRowZero)
|
||||
}
|
||||
|
||||
logger.Error(c, "query component info into postgresDB failed", "component_global_uuid", componentInfo.UUID, "error", err)
|
||||
|
|
@ -177,7 +177,7 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check uuid conditions", constant.ErrDeleteRowZero)
|
||||
err = fmt.Errorf("%w:please check uuid conditions", errcode.ErrDeleteRowZero)
|
||||
}
|
||||
|
||||
logger.Error(c, "delete component info into postgresDB failed", "component_global_uuid", componentInfo.UUID, "error", err)
|
||||
|
|
@ -201,7 +201,7 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check uuid conditions", constant.ErrDeleteRowZero)
|
||||
err = fmt.Errorf("%w:please check uuid conditions", errcode.ErrDeleteRowZero)
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("delete component info from table %s failed", modelStruct.ReturnTableName())
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"strconv"
|
||||
|
||||
"modelRT/alert"
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/logger"
|
||||
"modelRT/network"
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
// QueryRealTimeDataHandler define query real time data process API
|
||||
func QueryRealTimeDataHandler(c *gin.Context) {
|
||||
var targetLevel constant.AlertLevel
|
||||
var targetLevel constants.AlertLevel
|
||||
|
||||
alertManger := alert.GetAlertMangerInstance()
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ func QueryRealTimeDataHandler(c *gin.Context) {
|
|||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
targetLevel = constant.AlertLevel(level)
|
||||
targetLevel = constants.AlertLevel(level)
|
||||
events := alertManger.GetRangeEventsByLevel(targetLevel)
|
||||
|
||||
resp := network.SuccessResponse{
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ package handler
|
|||
import (
|
||||
"modelRT/logger"
|
||||
"modelRT/network"
|
||||
realtimedata "modelRT/real-time-data"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gorilla/websocket"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
realtimedata "modelRT/real-time-data"
|
||||
)
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"modelRT/config"
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
|
||||
"github.com/natefinch/lumberjack"
|
||||
"go.uber.org/zap"
|
||||
|
|
@ -41,7 +41,7 @@ func getLogWriter(mode, filename string, maxsize, maxBackup, maxAge int, compres
|
|||
}
|
||||
|
||||
syncConsole := zapcore.AddSync(os.Stderr)
|
||||
if mode == constant.DevelopmentLogMode {
|
||||
if mode == constants.DevelopmentLogMode {
|
||||
return syncConsole
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/orm"
|
||||
)
|
||||
|
||||
// SelectModelByType define select the data structure for parsing based on the input model type
|
||||
func SelectModelByType(modelType int) BasicModelInterface {
|
||||
if modelType == constant.BusbarType {
|
||||
if modelType == constants.BusbarType {
|
||||
return &orm.BusbarSection{}
|
||||
} else if modelType == constant.AsyncMotorType {
|
||||
} else if modelType == constants.AsyncMotorType {
|
||||
return &orm.AsyncMotor{}
|
||||
} else if modelType == constant.DemoType {
|
||||
} else if modelType == constants.DemoType {
|
||||
return &orm.Demo{}
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ package network
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"modelRT/constant"
|
||||
"modelRT/common/errcode"
|
||||
constants "modelRT/constant"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
|
@ -61,12 +62,12 @@ func ParseUUID(info TopologicChangeInfo) (TopologicUUIDChangeInfos, error) {
|
|||
UUIDChangeInfo.ChangeType = info.ChangeType
|
||||
|
||||
switch info.ChangeType {
|
||||
case constant.UUIDFromChangeType:
|
||||
case constants.UUIDFromChangeType:
|
||||
if info.NewUUIDFrom == info.OldUUIDFrom {
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constant.ErrUUIDFromCheckT1)
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constants.ErrUUIDFromCheckT1)
|
||||
}
|
||||
if info.NewUUIDTo != info.OldUUIDTo {
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constant.ErrUUIDToCheckT1)
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constants.ErrUUIDToCheckT1)
|
||||
}
|
||||
|
||||
oldUUIDFrom, err := uuid.FromString(info.OldUUIDFrom)
|
||||
|
|
@ -87,12 +88,12 @@ func ParseUUID(info TopologicChangeInfo) (TopologicUUIDChangeInfos, error) {
|
|||
}
|
||||
UUIDChangeInfo.OldUUIDTo = OldUUIDTo
|
||||
UUIDChangeInfo.NewUUIDTo = OldUUIDTo
|
||||
case constant.UUIDToChangeType:
|
||||
case constants.UUIDToChangeType:
|
||||
if info.NewUUIDFrom != info.OldUUIDFrom {
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constant.ErrUUIDFromCheckT2)
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constants.ErrUUIDFromCheckT2)
|
||||
}
|
||||
if info.NewUUIDTo == info.OldUUIDTo {
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constant.ErrUUIDToCheckT2)
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constants.ErrUUIDToCheckT2)
|
||||
}
|
||||
|
||||
oldUUIDFrom, err := uuid.FromString(info.OldUUIDFrom)
|
||||
|
|
@ -113,12 +114,12 @@ func ParseUUID(info TopologicChangeInfo) (TopologicUUIDChangeInfos, error) {
|
|||
return UUIDChangeInfo, fmt.Errorf("convert data from string type to uuid type failed,new uuid_to value:%s", info.NewUUIDTo)
|
||||
}
|
||||
UUIDChangeInfo.NewUUIDTo = newUUIDTo
|
||||
case constant.UUIDAddChangeType:
|
||||
case constants.UUIDAddChangeType:
|
||||
if info.OldUUIDFrom != "" {
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constant.ErrUUIDFromCheckT3)
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constants.ErrUUIDFromCheckT3)
|
||||
}
|
||||
if info.OldUUIDTo != "" {
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constant.ErrUUIDToCheckT3)
|
||||
return UUIDChangeInfo, fmt.Errorf("topologic change data check failed:%w", constants.ErrUUIDToCheckT3)
|
||||
}
|
||||
|
||||
newUUIDFrom, err := uuid.FromString(info.NewUUIDFrom)
|
||||
|
|
@ -133,7 +134,7 @@ func ParseUUID(info TopologicChangeInfo) (TopologicUUIDChangeInfos, error) {
|
|||
}
|
||||
UUIDChangeInfo.NewUUIDTo = newUUIDTo
|
||||
default:
|
||||
return UUIDChangeInfo, constant.ErrUUIDChangeType
|
||||
return UUIDChangeInfo, errcode.ErrUUIDChangeType
|
||||
}
|
||||
UUIDChangeInfo.Flag = info.Flag
|
||||
UUIDChangeInfo.Comment = info.Comment
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"modelRT/alert"
|
||||
"modelRT/config"
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/diagram"
|
||||
"modelRT/logger"
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ var AnchorFunc = func(poolConfig interface{}) {
|
|||
event := alert.Event{
|
||||
ComponentID: componentID,
|
||||
AnchorName: anchorName,
|
||||
Level: constant.InfoAlertLevel,
|
||||
Level: constants.InfoAlertLevel,
|
||||
Message: message,
|
||||
StartTime: time.Now().Unix(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import (
|
|||
"context"
|
||||
|
||||
"modelRT/config"
|
||||
"modelRT/constant"
|
||||
constants "modelRT/constant"
|
||||
"modelRT/diagram"
|
||||
"modelRT/logger"
|
||||
"modelRT/network"
|
||||
|
|
@ -35,7 +35,7 @@ func ReceiveChan(ctx context.Context) {
|
|||
}
|
||||
|
||||
componentType := component["component_type"].(int)
|
||||
if componentType != constant.DemoType {
|
||||
if componentType != constants.DemoType {
|
||||
logger.Error(ctx, "can not process real time data of component type not equal DemoType", "component_id", componentID)
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
dl "modelRT/distributedlock"
|
||||
"modelRT/distributedlock/constant"
|
||||
constants "modelRT/distributedlock/constant"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
|
@ -450,7 +450,7 @@ func TestRWLock2CWithRLockAndWLockFailed(t *testing.T) {
|
|||
// locker2加写锁锁
|
||||
duration = 10 * time.Second
|
||||
err = rwLocker2.WLock(ctx, duration)
|
||||
assert.Equal(t, constant.AcquireTimeoutErr, err)
|
||||
assert.Equal(t, constants.AcquireTimeoutErr, err)
|
||||
|
||||
err = rwLocker1.UnRLock(ctx)
|
||||
assert.Equal(t, nil, err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue