Code-Fight commented on code in PR #741:
URL:
https://github.com/apache/incubator-seata-go/pull/741#discussion_r1885614903
##########
pkg/saga/statemachine/statelang/parser/statemachine_config_parser.go:
##########
@@ -0,0 +1,127 @@
+package parser
Review Comment:
要带上apache的License 头,参考别的文件copy一个,或者参考根目录的 goimports.sh 下面所有的文件都检查一下
##########
pkg/saga/statemachine/statelang/parser/statemachine_config_parser.go:
##########
@@ -0,0 +1,127 @@
+package parser
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "gopkg.in/yaml.v3"
+ "io"
+ "os"
+ "path/filepath"
+)
+
+type ConfigParser interface {
Review Comment:
加一些注释,介绍下这个interface的作用,后续维护更方便
##########
pkg/saga/statemachine/statelang/parser/statemachine_config_parser.go:
##########
@@ -0,0 +1,127 @@
+package parser
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "gopkg.in/yaml.v3"
+ "io"
+ "os"
+ "path/filepath"
+)
+
+type ConfigParser interface {
+ Parse(configContent []byte) (*StateMachineObject, error)
+}
+
+type StateMachineConfigParser struct{}
+
+func NewStateMachineConfigParser() *StateMachineConfigParser {
+ return &StateMachineConfigParser{}
+}
+
+func (p *StateMachineConfigParser) checkConfigFile(configFilePath string)
error {
+ if _, err := os.Stat(configFilePath); err != nil {
+ if os.IsNotExist(err) {
Review Comment:
if os.IsNotExist(err) 放在上面上面的if外面,是不是更方便阅读?
##########
pkg/saga/statemachine/statelang/parser/statemachine_config_parser.go:
##########
@@ -0,0 +1,127 @@
+package parser
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "gopkg.in/yaml.v3"
+ "io"
+ "os"
+ "path/filepath"
+)
+
+type ConfigParser interface {
+ Parse(configContent []byte) (*StateMachineObject, error)
+}
+
+type StateMachineConfigParser struct{}
+
+func NewStateMachineConfigParser() *StateMachineConfigParser {
+ return &StateMachineConfigParser{}
+}
+
+func (p *StateMachineConfigParser) checkConfigFile(configFilePath string)
error {
+ if _, err := os.Stat(configFilePath); err != nil {
+ if os.IsNotExist(err) {
+ return fmt.Errorf("config file %s does not exist: %w",
configFilePath, err)
+ }
+ return fmt.Errorf("failed to access config file %s: %w",
configFilePath, err)
+ }
+ return nil
+}
+
+func (p *StateMachineConfigParser) readFile(configFilePath string) ([]byte,
error) {
+ file, _ := os.Open(configFilePath)
+ defer func(file *os.File) {
+ _ = file.Close()
+ }(file)
+
+ var buf bytes.Buffer
+ _, err := io.Copy(&buf, file)
+ if err != nil {
+ return nil, fmt.Errorf("failed to read config file %s: %w",
configFilePath, err)
+ }
+
+ return buf.Bytes(), nil
+}
+
+func (p *StateMachineConfigParser) getParser(configFilePath string)
(ConfigParser, error) {
+ fileExt := filepath.Ext(configFilePath)
+ switch fileExt {
+ case ".json":
Review Comment:
要不要兼容一些异常的情况? 比如:.JSON .YAML
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]