yjp il y a 2 mois
Parent
commit
41799b66eb

+ 2 - 0
go.mod

@@ -3,6 +3,7 @@ module git.sxidc.com/go-tools/api_binding
 go 1.21.3
 
 require (
+	git.sxidc.com/go-tools/utils v1.0.1
 	git.sxidc.com/service-supports/fserr v0.3.2
 	git.sxidc.com/service-supports/fslog v0.5.5
 	git.sxidc.com/service-supports/websocket v1.3.1
@@ -30,6 +31,7 @@ require (
 	github.com/olahol/melody v1.1.1 // indirect
 	github.com/pelletier/go-toml/v2 v2.1.0 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
+	github.com/satori/go.uuid v1.2.0 // indirect
 	github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
 	github.com/ugorji/go/codec v1.2.11 // indirect
 	go.uber.org/multierr v1.11.0 // indirect

+ 4 - 0
go.sum

@@ -1,3 +1,5 @@
+git.sxidc.com/go-tools/utils v1.0.1 h1:HQN+qCaTFfrZEWrwOkMC1+5YiczfiEG18qhb4kwJcZs=
+git.sxidc.com/go-tools/utils v1.0.1/go.mod h1:Cn+2J6AB1I4vGZlr6+Gap/DB/hkI5681fb2v6LJa0S8=
 git.sxidc.com/service-supports/fserr v0.3.2 h1:5/FCr8o2jd1kNsp5tH/ADjB9fr091JZXMMZ15ZvNZzs=
 git.sxidc.com/service-supports/fserr v0.3.2/go.mod h1:W54RoA71mfex+zARuH/iMnQPMnBXQ23qXXOkwUh2sVQ=
 git.sxidc.com/service-supports/fslog v0.5.5 h1:JDNcKUfbj44r4V4Mr4tDBTxD6RekWounO2Q59Q9toN0=
@@ -66,6 +68,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
+github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
 github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

+ 2 - 2
http_binding/binding_context/binding_context.go

@@ -2,7 +2,7 @@ package binding_context
 
 import (
 	"errors"
-	"git.sxidc.com/go-tools/api_binding/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	"git.sxidc.com/service-supports/fslog"
 	"github.com/gin-gonic/gin"
 	"io"
@@ -18,7 +18,7 @@ func (c *Context) GetPathParams(pathParamNames []string) ([]string, error) {
 	pathParamValues := make([]string, 0)
 	for _, paramName := range pathParamNames {
 		paramValue := c.Param(paramName)
-		if utils.IsStringEmpty(paramValue) {
+		if strutils.IsStringEmpty(paramValue) {
 			return nil, errors.New("没有传递路径参数" + paramName)
 		}
 

+ 6 - 6
http_binding/http_binding.go

@@ -6,7 +6,7 @@ import (
 	"git.sxidc.com/go-tools/api_binding/http_binding/middleware"
 	"git.sxidc.com/go-tools/api_binding/http_binding/request"
 	"git.sxidc.com/go-tools/api_binding/http_binding/response"
-	"git.sxidc.com/go-tools/api_binding/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	"git.sxidc.com/service-supports/fserr"
 	"git.sxidc.com/service-supports/fslog"
 	"github.com/gin-gonic/gin"
@@ -25,7 +25,7 @@ type Binding struct {
 // NewBinding 创建版本对应的binding
 func NewBinding(apiVersion string, middlewares ...middleware.Func) *Binding {
 	apiPrefix := urlPrefix + "/api"
-	if utils.IsStringNotEmpty(apiVersion) && apiVersion != "root" {
+	if strutils.IsStringNotEmpty(apiVersion) && apiVersion != "root" {
 		apiPrefix += "/" + apiVersion
 	}
 
@@ -45,11 +45,11 @@ func NewBinding(apiVersion string, middlewares ...middleware.Func) *Binding {
 type HandleFunc func(c *binding_context.Context)
 
 func (binding *Binding) AddHandler(method string, relativePath string, handleFunctions ...HandleFunc) error {
-	if utils.IsStringEmpty(method) {
+	if strutils.IsStringEmpty(method) {
 		return errors.New("没有传递方法名")
 	}
 
-	if utils.IsStringEmpty(relativePath) {
+	if strutils.IsStringEmpty(relativePath) {
 		return errors.New("没有传递相对路径")
 	}
 
@@ -131,11 +131,11 @@ type BindItem[I any, O any] struct {
 }
 
 func (item *BindItem[I, O]) bind(routerGroup *gin.RouterGroup, middlewares ...middleware.Func) {
-	if utils.IsStringEmpty(item.Path) {
+	if strutils.IsStringEmpty(item.Path) {
 		panic("需要指定路径")
 	}
 
-	if utils.IsStringEmpty(item.Method) {
+	if strutils.IsStringEmpty(item.Method) {
 		panic("需要指定方法")
 	}
 

+ 4 - 4
mqtt_binding/mqtt_binding.go

@@ -7,7 +7,7 @@ import (
 	"git.sxidc.com/go-tools/api_binding/mqtt_binding/mqtt_client/router"
 	"git.sxidc.com/go-tools/api_binding/mqtt_binding/request"
 	"git.sxidc.com/go-tools/api_binding/mqtt_binding/response"
-	"git.sxidc.com/go-tools/api_binding/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	"git.sxidc.com/service-supports/fslog"
 	"reflect"
 	"strings"
@@ -26,7 +26,7 @@ type Binding struct {
 // NewBinding 创建版本对应的binding
 func NewBinding(apiVersion string, responseIdentifier response.Identifier, handlers ...router.Handler) *Binding {
 	group := topicPrefix
-	if utils.IsStringNotEmpty(apiVersion) && apiVersion != "root" {
+	if strutils.IsStringNotEmpty(apiVersion) && apiVersion != "root" {
 		group += "/" + apiVersion
 	}
 
@@ -48,7 +48,7 @@ func Bind[I any, O any](b *Binding, item *BindItem[I, O], handlers ...router.Han
 }
 
 func (binding *Binding) AddHandler(topic string, handlers ...router.Handler) error {
-	if utils.IsStringEmpty(topic) {
+	if strutils.IsStringEmpty(topic) {
 		return errors.New("没有传递主题")
 	}
 
@@ -85,7 +85,7 @@ type BindItem[I any, O any] struct {
 }
 
 func (item *BindItem[I, O]) bind(r *router.Router, bindingResponseIdentifier response.Identifier, handlers ...router.Handler) {
-	if utils.IsStringEmpty(item.Topic) {
+	if strutils.IsStringEmpty(item.Topic) {
 		panic("需要指定主题")
 	}
 

+ 6 - 6
mqtt_binding/mqtt_client/mqtt_client.go

@@ -4,7 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"git.sxidc.com/go-tools/api_binding/mqtt_binding/mqtt_client/router"
-	"git.sxidc.com/go-tools/api_binding/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	mqtt "github.com/eclipse/paho.mqtt.golang"
 	"sync"
 	"time"
@@ -23,19 +23,19 @@ type MqttClientOptions struct {
 }
 
 func (opts *MqttClientOptions) check() error {
-	if utils.IsStringEmpty(opts.UserName) {
+	if strutils.IsStringEmpty(opts.UserName) {
 		return errors.New("必须传递用户名")
 	}
 
-	if utils.IsStringEmpty(opts.Password) {
+	if strutils.IsStringEmpty(opts.Password) {
 		return errors.New("必须传递密码")
 	}
 
-	if utils.IsStringEmpty(opts.Address) {
+	if strutils.IsStringEmpty(opts.Address) {
 		return errors.New("必须传递地址")
 	}
 
-	if utils.IsStringEmpty(opts.ClientID) {
+	if strutils.IsStringEmpty(opts.ClientID) {
 		return errors.New("必须传递客户端ID")
 	}
 
@@ -187,7 +187,7 @@ func (c *MqttClient) GetRouter(group string, handlers []router.Handler) *router.
 
 func (c *MqttClient) Response(item *router.Item, responseIdentifier string, data []byte) error {
 	replyTopic := item.Topic + "/reply"
-	if utils.IsStringNotEmpty(responseIdentifier) {
+	if strutils.IsStringNotEmpty(responseIdentifier) {
 		replyTopic = fmt.Sprintf("%s/%s/reply", item.Topic, responseIdentifier)
 	}
 

+ 2 - 2
mqtt_binding/mqtt_client/router/router.go

@@ -2,7 +2,7 @@ package router
 
 import (
 	"errors"
-	"git.sxidc.com/go-tools/api_binding/utils"
+	"git.sxidc.com/go-tools/utils/strutils"
 	"sync"
 )
 
@@ -104,7 +104,7 @@ type Item struct {
 }
 
 func NewItem(topic string, handlers []Handler) (*Item, error) {
-	if utils.IsStringEmpty(topic) {
+	if strutils.IsStringEmpty(topic) {
 		return nil, errors.New("没有传递主题")
 	}
 

+ 0 - 11
utils/utils.go

@@ -1,11 +0,0 @@
-package utils
-
-import "strings"
-
-func IsStringEmpty(s string) bool {
-	return strings.Trim(s, " ") == ""
-}
-
-func IsStringNotEmpty(s string) bool {
-	return strings.Trim(s, " ") != ""
-}