From 6544fb43498c495fc17c211e4837aee7c9c2c15e Mon Sep 17 00:00:00 2001 From: zhangming Date: Tue, 12 Nov 2024 02:50:52 +0800 Subject: [PATCH] update-namespace --- store/postgresql/namespace.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/store/postgresql/namespace.go b/store/postgresql/namespace.go index 86b2d00..f8aab9a 100644 --- a/store/postgresql/namespace.go +++ b/store/postgresql/namespace.go @@ -19,9 +19,11 @@ package postgresql import ( "database/sql" + "encoding/json" "errors" "fmt" "github.com/polarismesh/polaris/common/utils" + "strconv" "time" "github.com/polarismesh/polaris/common/model" @@ -281,8 +283,10 @@ func namespaceFetchRows(rows *sql.Rows) ([]*model.Namespace, error) { defer rows.Close() var ( - out []*model.Namespace - flag int + out []*model.Namespace + ctimeStr, mtimeStr string + flag int + serviceExportTo string ) for rows.Next() { @@ -293,13 +297,29 @@ func namespaceFetchRows(rows *sql.Rows) ([]*model.Namespace, error) { &space.Token, &space.Owner, &flag, - &space.CreateTime, - &space.ModifyTime) + &ctimeStr, + &mtimeStr, + &serviceExportTo) if err != nil { log.Errorf("[Store][database] fetch namespace rows scan err: %s", err.Error()) return nil, err } + // 将字符串转换为int64 + ctimeFloat, err := strconv.ParseFloat(ctimeStr, 64) + if err != nil { + return nil, fmt.Errorf("failed to parse create_time: %v", err) + } + mtimeFloat, err := strconv.ParseFloat(mtimeStr, 64) + if err != nil { + return nil, fmt.Errorf("failed to parse modify_time: %v", err) + } + space.CreateTime = time.Unix(int64(ctimeFloat), 0) + space.ModifyTime = time.Unix(int64(mtimeFloat), 0) + + space.ServiceExportTo = map[string]struct{}{} + _ = json.Unmarshal([]byte(serviceExportTo), &space.ServiceExportTo) + space.Valid = true if flag == 1 { space.Valid = false