Browse Source

删除内部使用的utils

yjp 1 year ago
parent
commit
2936969c44

+ 4 - 4
pipeline/component/component.go

@@ -2,7 +2,7 @@ package component
 
 import (
 	"errors"
-	"git.sxidc.com/go-tools/utils/pipeline/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	"sync"
 )
 
@@ -26,7 +26,7 @@ func RegisterComponentBuilders(builders ...Builder) error {
 
 	for _, builder := range builders {
 		nodeType := builder.ProductType()
-		if utils.IsStringEmpty(nodeType) {
+		if strutils.IsStringEmpty(nodeType) {
 			return errors.New("节点类型名称不能为空")
 		}
 
@@ -52,11 +52,11 @@ func UnRegisterComponents(typeNames []string) {
 }
 
 func BuildComponent(typeName string, name string, buildParams map[string]any, runParams map[string]any) (Component, error) {
-	if utils.IsStringEmpty(typeName) {
+	if strutils.IsStringEmpty(typeName) {
 		return nil, errors.New("没有传递类型名称")
 	}
 
-	if utils.IsStringEmpty(name) {
+	if strutils.IsStringEmpty(name) {
 		return nil, errors.New("没有传递名称")
 	}
 

+ 3 - 3
pipeline/component/flow/flow.go

@@ -3,7 +3,7 @@ package flow
 import (
 	"errors"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
-	"git.sxidc.com/go-tools/utils/pipeline/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 )
 
 type SubComponentBuildParams struct {
@@ -14,11 +14,11 @@ type SubComponentBuildParams struct {
 }
 
 func (params *SubComponentBuildParams) Check(parentNodeType string) error {
-	if utils.IsStringEmpty(params.Type) {
+	if strutils.IsStringEmpty(params.Type) {
 		return errors.New(parentNodeType + "没有传递子节点类型")
 	}
 
-	if utils.IsStringEmpty(params.Name) {
+	if strutils.IsStringEmpty(params.Name) {
 		return errors.New(parentNodeType + "没有传递子节点名称")
 	}
 

+ 5 - 5
pipeline/definition.go

@@ -4,7 +4,7 @@ import (
 	"errors"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"git.sxidc.com/go-tools/utils/pipeline/component/flow"
-	"git.sxidc.com/go-tools/utils/pipeline/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	"github.com/fatih/structs"
 )
 
@@ -14,7 +14,7 @@ type Definition struct {
 }
 
 func (def *Definition) Check() error {
-	if utils.IsStringEmpty(def.Name) {
+	if strutils.IsStringEmpty(def.Name) {
 		return errors.New("流水线没有传递名称")
 	}
 
@@ -40,11 +40,11 @@ type ComponentDefinition struct {
 }
 
 func (def *ComponentDefinition) Check() error {
-	if utils.IsStringEmpty(def.Type) {
+	if strutils.IsStringEmpty(def.Type) {
 		return errors.New("组件没有传递类型")
 	}
 
-	if utils.IsStringEmpty(def.Name) {
+	if strutils.IsStringEmpty(def.Name) {
 		return errors.New("组件没有传递名称")
 	}
 
@@ -78,7 +78,7 @@ func (def *Definition) NewPipeline() (*Pipeline, error) {
 }
 
 func newPipelineWithBuildParams(name string, params *flow.SeqBuildParams) (*Pipeline, error) {
-	if utils.IsStringEmpty(name) {
+	if strutils.IsStringEmpty(name) {
 		return nil, errors.New("没有传递流水线的名称")
 	}
 

+ 8 - 7
pipeline/pipeline.go

@@ -2,9 +2,10 @@ package pipeline
 
 import (
 	"errors"
+	"git.sxidc.com/go-tools/utils/fileutils"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
 	"git.sxidc.com/go-tools/utils/pipeline/component/flow"
-	"git.sxidc.com/go-tools/utils/pipeline/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	"gopkg.in/yaml.v3"
 	"os"
 )
@@ -42,11 +43,11 @@ func (p *Pipeline) Run(globalRunParams map[string]any, dynamicParams map[string]
 }
 
 func NewPipelineFromYaml(yamlPath string) (*Pipeline, error) {
-	if utils.IsStringEmpty(yamlPath) {
+	if strutils.IsStringEmpty(yamlPath) {
 		return nil, errors.New("没有传递流水线定义文件")
 	}
 
-	if !utils.PathExists(yamlPath) {
+	if !fileutils.PathExists(yamlPath) {
 		return nil, errors.New("流水线定义文件不存在")
 	}
 
@@ -65,7 +66,7 @@ func NewPipelineFromYaml(yamlPath string) (*Pipeline, error) {
 }
 
 func NewPipelineFromYamlStr(yamlStr string) (*Pipeline, error) {
-	if utils.IsStringEmpty(yamlStr) {
+	if strutils.IsStringEmpty(yamlStr) {
 		return nil, errors.New("没有传递流水线定义")
 	}
 
@@ -79,11 +80,11 @@ func NewPipelineFromYamlStr(yamlStr string) (*Pipeline, error) {
 }
 
 func LoadDynamicParamsFromYaml(yamlPath string) (map[string]any, error) {
-	if utils.IsStringEmpty(yamlPath) {
+	if strutils.IsStringEmpty(yamlPath) {
 		return nil, errors.New("没有传递流水线动态参数文件不存在")
 	}
 
-	if !utils.PathExists(yamlPath) {
+	if !fileutils.PathExists(yamlPath) {
 		return nil, errors.New("流水线动态参数文件不存在")
 	}
 
@@ -102,7 +103,7 @@ func LoadDynamicParamsFromYaml(yamlPath string) (map[string]any, error) {
 }
 
 func LoadDynamicParamsFromYamlStr(yamlStr string) (map[string]any, error) {
-	if utils.IsStringEmpty(yamlStr) {
+	if strutils.IsStringEmpty(yamlStr) {
 		return nil, errors.New("没有传递流水线动态参数不存在")
 	}
 

+ 2 - 2
pipeline/test/test_node/bool.go

@@ -4,7 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"git.sxidc.com/go-tools/utils/pipeline/component"
-	"git.sxidc.com/go-tools/utils/pipeline/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	"github.com/mitchellh/mapstructure"
 	"math/rand"
 )
@@ -38,7 +38,7 @@ func (n *BoolNode) Run(globalRunParams *component.GlobalRunParams, dynamicParams
 				return nil, errors.New(TypeBool + "节点运行时参数Decode失败: " + err.Error())
 			}
 
-			if utils.IsStringEmpty(params.Operation) {
+			if strutils.IsStringEmpty(params.Operation) {
 				params.Operation = BoolOperationPass
 			}
 

+ 0 - 27
pipeline/utils/utils.go

@@ -1,27 +0,0 @@
-package utils
-
-import (
-	"os"
-	"strings"
-)
-
-func IsStringEmpty(s string) bool {
-	return strings.Trim(s, " ") == ""
-}
-
-func IsStringNotEmpty(s string) bool {
-	return strings.Trim(s, " ") != ""
-}
-
-func PathExists(path string) bool {
-	_, err := os.Stat(path)
-	if err == nil {
-		return true
-	}
-
-	if os.IsNotExist(err) {
-		return false
-	}
-
-	return false
-}