@@ -37,6 +37,11 @@ import (
3737
3838// CreateConfigFile 创建配置文件
3939func (s * Server ) CreateConfigFile (ctx context.Context , req * apiconfig.ConfigFile ) * apiconfig.ConfigResponse {
40+ savaData := model .ToConfigFileStore (req )
41+ if errResp := s .chains .BeforeCreateFile (ctx , savaData ); errResp != nil {
42+ return errResp
43+ }
44+
4045 if rsp := s .prepareCreateConfigFile (ctx , req ); rsp .Code .Value != api .ExecuteSuccess {
4146 return rsp
4247 }
@@ -50,7 +55,7 @@ func (s *Server) CreateConfigFile(ctx context.Context, req *apiconfig.ConfigFile
5055 _ = tx .Rollback ()
5156 }()
5257
53- resp := s .handleCreateConfigFile (ctx , tx , req )
58+ resp := s ._handleCreateConfigFile (ctx , tx , savaData )
5459 if resp .GetCode ().GetValue () != uint32 (apimodel .Code_ExecuteSuccess ) {
5560 return resp
5661 }
@@ -63,30 +68,37 @@ func (s *Server) CreateConfigFile(ctx context.Context, req *apiconfig.ConfigFile
6368 return resp
6469}
6570
71+ // handleCreateConfigFile .
6672func (s * Server ) handleCreateConfigFile (ctx context.Context , tx store.Tx ,
6773 req * apiconfig.ConfigFile ) * apiconfig.ConfigResponse {
6874
69- data , err := s .storage .GetConfigFileTx (tx , req .GetNamespace ().GetValue (), req .GetGroup ().GetValue (),
70- req .GetName ().GetValue ())
75+ savaData := model .ToConfigFileStore (req )
76+ if errResp := s .chains .BeforeCreateFile (ctx , savaData ); errResp != nil {
77+ return errResp
78+ }
79+
80+ return s ._handleCreateConfigFile (ctx , tx , savaData )
81+ }
82+
83+ func (s * Server ) _handleCreateConfigFile (ctx context.Context , tx store.Tx ,
84+ saveData * model.ConfigFile ) * apiconfig.ConfigResponse {
85+
86+ data , err := s .storage .GetConfigFileTx (tx , saveData .Namespace , saveData .Group ,
87+ saveData .Name )
7188 if err != nil {
7289 log .Error ("[Config][File] create config file when get save data." , utils .RequestID (ctx ),
73- utils .ZapNamespace (req . GetNamespace (). GetValue ()) , utils .ZapGroup (req . GetGroup (). GetValue () ),
74- utils .ZapFileName (req . GetName (). GetValue () ), zap .Error (err ))
90+ utils .ZapNamespace (saveData . Namespace ) , utils .ZapGroup (saveData . Group ),
91+ utils .ZapFileName (saveData . Name ), zap .Error (err ))
7592 return api .NewConfigResponse (commonstore .StoreCode2APICode (err ))
7693 }
7794 if data != nil {
7895 return api .NewConfigResponse (apimodel .Code_ExistedResource )
7996 }
80-
81- savaData := model .ToConfigFileStore (req )
82- if errResp := s .chains .BeforeCreateFile (ctx , savaData ); errResp != nil {
83- return errResp
84- }
8597 // 创建配置文件
86- if err := s .storage .CreateConfigFileTx (tx , savaData ); err != nil {
98+ if err := s .storage .CreateConfigFileTx (tx , saveData ); err != nil {
8799 log .Error ("[Config][File] create config file error." , utils .RequestID (ctx ),
88- utils .ZapNamespace (req . GetNamespace (). GetValue ()) , utils .ZapGroup (req . GetGroup (). GetValue () ),
89- utils .ZapFileName (req . GetName (). GetValue () ), zap .Error (err ))
100+ utils .ZapNamespace (saveData . Namespace ) , utils .ZapGroup (saveData . Group ),
101+ utils .ZapFileName (saveData . Name ), zap .Error (err ))
90102 return api .NewConfigResponse (commonstore .StoreCode2APICode (err ))
91103 }
92104 return api .NewConfigResponse (apimodel .Code_ExecuteSuccess )
0 commit comments