質問

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