gin-gonic

How can I pass a var between routes funcs and change it in every controller?

柔情痞子 提交于 2020-06-23 18:05:48
问题 I want to pass var and change it globally in every controller between routes so if controller1 change var to "as" I want controller2 to use the new value of the var = "as". How can I do it? something like this main.go: var test []string func NewRouter() *gin.Engine { gin.SetMode(gin.ReleaseMode) r := gin.New() r.GET("/ping", gets(test)) r.Run(":6030") return r } controller.go: func gets(test) gin.HandlerFunc { fn := func(c *gin.Context){ // Here I want to change my var (test) and I want to

How can I pass a var between routes funcs and change it in every controller?

拥有回忆 提交于 2020-06-23 18:04:49
问题 I want to pass var and change it globally in every controller between routes so if controller1 change var to "as" I want controller2 to use the new value of the var = "as". How can I do it? something like this main.go: var test []string func NewRouter() *gin.Engine { gin.SetMode(gin.ReleaseMode) r := gin.New() r.GET("/ping", gets(test)) r.Run(":6030") return r } controller.go: func gets(test) gin.HandlerFunc { fn := func(c *gin.Context){ // Here I want to change my var (test) and I want to

Apply custom html tag to gin-gonic response

女生的网名这么多〃 提交于 2019-12-11 14:32:08
问题 I'm trying to prettify the response printed trough gin-gonic . From a go POV, i populate a struct with a string. My scope is to apply html tag to the input string. // Struct for prettify response type DocResponse struct { Filename string `json:"filename"` Url string `json:"url"` Content string `json:"data"` } var response []DocResponse // iterating data for populate struct for i := range found { //NOTE: Apply a <div> tag tmp := DocResponse{Filename: found[i], Url: `<div>http://127.0.0.1:8080