-
-
Save parzibyte/ceb389ed91824c9540ff33844c96f78d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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