문제

I'm trying to deploy my first golang app on GAE. For some reasons the products handler doesn't resolve and I get 404 errors. Am I missing something ?

package test
import "github.com/gorilla/mux"
import (
    "fmt"
    "net/http"
)



func main() {
    r := mux.NewRouter()
    r.HandleFunc("/products", ProductsHandler)
    http.Handle("/", r)

       e := http.ListenAndServe(":8080", r)
    if e != nil {
      println(e.Error())
    }
}

func ProductsHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, you!")
}
도움이 되었습니까?

해결책

Go on AppEngine will automatically listen on the correct port and serve the http.DefaultServeMux. Change your main function to an init and remove the serve logic and you should be all set.

Read through the Getting Started section on Requests and HTTP for more detail.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top