user5833717
user5833717

Reputation:

Go app runs fine locally, produces 404 when running goapp serve

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

Upvotes: 0

Views: 86

Answers (1)

tx802
tx802

Reputation: 3564

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.

Upvotes: 2

Related Questions