Application failed to respond (with hello world in Golang)
hi!, i new here, am try to deploy a simple runtine in golang , it's a simple web app, so i try deploy but don't work, this is my "site" https://portalcomunidadretro.up.railway.app/, my code is :
------------------------------------------
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("here!")
http.ServeFile(w, r, "static/index.html")
})
http.HandleFunc("/saludo", func(w http.ResponseWriter, r *http.Request) {
fmt.Println("Buscando index!!")
fmt.Fprintf(w, "All OK!!")
})
fmt.Println("Servidor escuchando en el puerto :80, sin novedades")
http.ListenAndServe(":80", nil)
}
-------------------------------------------
according to railway, everything is ok and ready to work, but when I enter the url, it tells me that there is an error, i need help
Solution:Jump to solution
you need to listen on the
PORT
environment variable -
```
port := cmp.Or(os.Getenv("PORT"), "80")
http.ListenAndServe(":" + port, nil)...8 Replies
371a1282-6fbe-4e47-8656-d10aec6b432c
this is my project ID
Solution
you need to listen on the
PORT
environment variable -
what is cmp.Or ??
thanks, this method don't exist in my import
i think it was introduced in go 1.22
oka, thanks again
it's fine , thanks
no problem!