animeic il y a 1 an
Parent
commit
e3ef6cf84a
4 fichiers modifiés avec 20 ajouts et 2 suppressions
  1. 17 0
      baishuihu/api/printr.go
  2. 1 0
      baishuihu/go.mod
  3. 2 0
      baishuihu/go.sum
  4. 0 2
      baishuihu/main.go

+ 17 - 0
baishuihu/api/printr.go

@@ -1,10 +1,27 @@
 package api
 
 import (
+	"fmt"
+	"net/http"
+	"time"
+
 	"github.com/gin-gonic/gin"
 )
 
 func Printr(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	c.Header("Content-Type", "text/event-stream")
+	c.Header("Cache-Control", "no-cache")
+	c.Header("Connection", "keep-alive")
+	c.Header("Access-Control-Allow-Origin", "*")
+
+	for {
+		// c.Request.Write()
+		fmt.Fprintf(c.Writer, "data: %s\n\n", time.Now().Format(time.Stamp))
+		c.Writer.(http.Flusher).Flush()
+		time.Sleep(1 * time.Second)
+		fmt.Println(time.Now().Format(time.Stamp))
+	}
+
 	map1 := map[string]string{"a": "1234"}
 	println(map1["b"] == "")
 	println(map1["a"])

+ 1 - 0
baishuihu/go.mod

@@ -53,6 +53,7 @@ require (
 	github.com/hashicorp/errwrap v1.1.0 // indirect
 	github.com/hashicorp/go-multierror v1.1.1 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
+	github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.9+incompatible
 	github.com/jessevdk/go-flags v1.5.0 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
 	github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect

+ 2 - 0
baishuihu/go.sum

@@ -725,6 +725,8 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
 github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
 github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
+github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.9+incompatible h1:zUhCrGMMpJxZGAB30GbQzluDhQuPENxRQfxss7KlpKU=
+github.com/huaweicloud/huaweicloud-sdk-go-obs v3.23.9+incompatible/go.mod h1:l7VUhRbTKCzdOacdT4oWCwATKyvZqUOlOqr0Ous3k4s=
 github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=

+ 0 - 2
baishuihu/main.go

@@ -30,10 +30,8 @@ func BuildApp() *dig.Container {
 }
 
 func main() {
-
 	flag.Parse()
 	app := BuildApp()
-
 	comm.AppMongoMiration()
 
 	err := app.Invoke(func(svc *api.Service, bus *comm.NatsBus) error {