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