Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 12, 2020 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ceb389ed91824c9540ff33844c96f78d to your computer and use it in GitHub Desktop.
Save parzibyte/ceb389ed91824c9540ff33844c96f78d to your computer and use it in GitHub Desktop.
package main
import (
"github.com/gorilla/mux"
"log"
"net/http"
"time"
)
func main() {
// Ping database
bd, err := getDB()
if err != nil {
log.Printf("Error with database" + err.Error())
return
} else {
err = bd.Ping()
if err != nil {
log.Printf("Error making connection to DB. Please check credentials. The error is: " + err.Error())
return
}
}
// Define routes
router := mux.NewRouter()
setupRoutesForVideoGames(router)
// .. here you can define more routes
// ...
// for example setupRoutesForGenres(router)
// Setup and start server
port := ":8000"
server := &http.Server{
Handler: router,
Addr: port,
// timeouts so the server never waits forever...
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Printf("Server started at %s", port)
log.Fatal(server.ListenAndServe())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment