ソースを参照

添加send函数

yjp 1 年間 前
コミット
6e6775735d
1 ファイル変更27 行追加0 行削除
  1. 27 0
      http_binding/response/response.go

+ 27 - 0
http_binding/response/response.go

@@ -6,6 +6,7 @@ import (
 	"git.sxidc.com/service-supports/fserr"
 	"git.sxidc.com/service-supports/fslog"
 	"git.sxidc.com/service-supports/websocket"
+	"net/http"
 )
 
 func SendMsgResponse(c *binding_context.Context, statusCode int, _ any, err error) {
@@ -136,3 +137,29 @@ func WSSendMessage(groupID string, obj any) {
 		return
 	}
 }
+
+func SendString(c *binding_context.Context, statusCode int, data string, err error) {
+	if err != nil {
+		c.String(http.StatusOK, err.Error())
+		return
+	}
+
+	c.String(http.StatusOK, data)
+}
+
+func WriteBytes(c *binding_context.Context, statusCode int, bytes []byte, err error) {
+	if err != nil {
+		c.AbortWithStatus(statusCode)
+		return
+	}
+
+	_, err = c.Writer.Write(bytes)
+	if err != nil {
+		c.AbortWithStatus(statusCode)
+		return
+	}
+}
+
+func SendMapXMLResponseIgnoreError(c *binding_context.Context, statusCode int, data map[string]any, _ error) {
+	c.XML(statusCode, data)
+}