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
No description
Solution:
you need to listen on the PORT environment variable - ``` port := cmp.Or(os.Getenv("PORT"), "80") http.ListenAndServe(":" + port, nil)...
Jump to solution
8 Replies
FernandoMB
FernandoMBOP7mo ago
371a1282-6fbe-4e47-8656-d10aec6b432c this is my project ID
Solution
Brody
Brody7mo ago
you need to listen on the PORT environment variable -
port := cmp.Or(os.Getenv("PORT"), "80")

http.ListenAndServe(":" + port, nil)
port := cmp.Or(os.Getenv("PORT"), "80")

http.ListenAndServe(":" + port, nil)
FernandoMB
FernandoMBOP7mo ago
what is cmp.Or ??
FernandoMB
FernandoMBOP7mo ago
thanks, this method don't exist in my import
No description
Brody
Brody7mo ago
i think it was introduced in go 1.22
FernandoMB
FernandoMBOP7mo ago
oka, thanks again it's fine , thanks
Brody
Brody7mo ago
no problem!
Want results from more Discord servers?
Add your server