Вопрос

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