2

I need to send a parameter to the page like this (every time I call a new chat it will have a different code)

http://192.168.0.10:3000/chat.html/**?mycode1**

http://192.168.0.10:3000/chat.html/**?mycode2**

Question: How and where are the parameters received on the server?

//--
import (
    socketio github.com/googollee/go-socket.io
    github.com/labstack/echo/v4
    github.com/labstack/echo/v4/middleware
    golang.org/x/crypto/acme/autocert
)

func main() {

    //----------------------
    // socket
    //----------------------
    server, err := socketio.NewServer(nil)
    if err != nil {
        log.Fatal(err)
    }   
    server.OnConnect("/", func(so socketio.Conn) error {...})
    server.OnEvent("/", "register", func(so socketio.Conn, name string) {...})
    server.OnEvent("/", "chat message", func(so socketio.Conn, msg string) {...})
    server.OnError("/", func(s socketio.Conn, e error) {...})
    server.OnDisconnect("/", func(s socketio.Conn, reason string) {...})
    go server.Serve()
    defer server.Close()


    //----------------------
    //-- server echo 
    //----------------------
    e := echo.New()

    port := os.Getenv("PORT")
    if port == "" {
        port = "3000"
    }

    // routes   
    e.Static("/", "public")
    e.GET("/socket.io/:id", func(context echo.Context) error {
        aa := context.Param("id")
        //aa := context.QueryParam("id")
        fmt.Printf("XXXXXXXXXXX esto es el parametro %v \n", aa)

        server.ServeHTTP(context.Response(), context.Request())
        return nil
    })
    
    // ok this work no parameter
    //  e.Any("/socket.io/", func(context echo.Context) error {
    //  server.ServeHTTP(context.Response(), context.Request())
    //  return nil
    // })

    //-- ejecucion del servidor 
    e.Logger.Fatal(e.Start(":" + port))
}
cesin
  • 99
  • 5

1 Answers1

1

I want to send a parameter to the html

a. (img1) Place the http://192.168.0.10:3000/chat/15 (id=15 is parameter)

b. (img2) In parameter it is received (by "labstack/echo/v4") in the function e.GET("chat/:id", func(c echo.Context) error {} Here I already have the value. Now, how do I pass the id (15) to the html? I want to send you the id=15

c. This return c.Redirect(http.StatusTemporaryRedirect, "/chat.html") what I do is load the following http://192.168.0.10:3000/chat.html

d. (img3) Here the parameter (id=15) must arrive or somehow (img4) server.OnConnect("/", func(so socketio.Conn) error {...})

enter image description here

cesin
  • 99
  • 5