douya6606 2016-03-25 20:33
浏览 117
已采纳

Go应用在本地运行良好,运行GoApp服务时产生404

I have a written a REST API using the Gorilla mux package and all data is stored in a MySQL database. I'm using the go-sql-driver/mysql package to access it.

When I compile and run the bin directly, it works as expected.

This is my first attepmt at deploying about to google cloud services, so I'm not familair with any special setup thatr needs to occur to make this work.

All code can be found at cobraclamp/hotswapper-api

NOTE: I'm aware that the InitDB in main has boilerplate credentials, they are properly set in the local and production projects

  • 写回答

1条回答 默认 最新

  • duancashi1362 2016-03-26 09:09
    关注

    I haven't trawled through all your code, but I guess the problem is you initialise your router in main.

    As per the App Engine go SDK docs and the Gorilla mux docs, you need to do this in an init() function:

    Or, for Google App Engine, register it in a init() function:

    func init() {
        http.Handle("/", router)
    }
    

    If you don't do this I guess your app will get a 404 for any route.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?