Application failed to respond (with hello world in Golang)
fmateluna
TRIALOP

2 years ago

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

11 Replies

fmateluna
TRIALOP

2 years ago

371a1282-6fbe-4e47-8656-d10aec6b432c


fmateluna
TRIALOP

2 years ago

this is my project ID


brody
EMPLOYEE

2 years ago

you need to listen on the PORT environment variable -

port := cmp.Or(os.Getenv("PORT"), "80")

http.ListenAndServe(":" + port, nil)

fmateluna
TRIALOP

2 years ago

what is cmp.Or ??


brody
EMPLOYEE

2 years ago


fmateluna
TRIALOP

2 years ago

thanks, this method don't exist in my import

1237129154437185500


brody
EMPLOYEE

2 years ago

i think it was introduced in go 1.22


fmateluna
TRIALOP

2 years ago

oka, thanks again


fmateluna
TRIALOP

2 years ago

it's fine , thanks


brody
EMPLOYEE

2 years ago

no problem!


fmateluna
TRIALOP

2 years ago

so, how add way to compiled my project?

2024/05/06 20:23:37 Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub

where is the deploy yml?


Loading...