go

Can I setup multi port from one web app with Go?


As I know, I can run simple web server with Golang just use http package, like

http.ListenAndServe(PORT, nil)

where PORT is TCP address to listen.

Can I use PORT as PORTS, for example http.ListenAndServe(":80, :8080", nil) from one application?

Possible my question is stupid, but "Who don't ask, He will not get answer!"


Solution

  • No, you cannot.

    You can however start multiple listeners on different ports

    go http.ListenAndServe(PORT, handlerA)
    http.ListenAndServe(PORT, handlerB)