Minor refactoring
This commit is contained in:
parent
dc66c070d6
commit
b38df1c07d
|
|
@ -17,20 +17,24 @@ const baseURL = "/api"
|
||||||
const apiVersion = "/v1"
|
const apiVersion = "/v1"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
|
||||||
|
|
||||||
// Read all configurations
|
// Read all configurations
|
||||||
parseConfig()
|
parseConfig()
|
||||||
|
|
||||||
// Initialize the database
|
// Initialize the database
|
||||||
dialect := viper.GetString("datastore.dialect")
|
initializeDatastore()
|
||||||
storage.StorageEngine, err = storage.CreateDatastore(dialect)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Errorf("Exception while creating datastore"))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Run any migrations on the datastore
|
||||||
runMigrations()
|
runMigrations()
|
||||||
|
|
||||||
|
router := intializeServer()
|
||||||
|
|
||||||
|
host := viper.GetString("server.host")
|
||||||
|
port := viper.GetString("server.port")
|
||||||
|
log.Fatal(http.ListenAndServe(host+":"+port, router))
|
||||||
|
}
|
||||||
|
|
||||||
|
func intializeServer() *httprouter.Router {
|
||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
|
|
||||||
// Account CRUD Endpoints
|
// Account CRUD Endpoints
|
||||||
|
|
@ -43,9 +47,17 @@ func main() {
|
||||||
// Page CRUD Endpoints
|
// Page CRUD Endpoints
|
||||||
|
|
||||||
// Query CRUD Endpoints
|
// Query CRUD Endpoints
|
||||||
host := viper.GetString("server.host")
|
|
||||||
port := viper.GetString("server.port")
|
return router
|
||||||
log.Fatal(http.ListenAndServe(host+":"+port, router))
|
}
|
||||||
|
|
||||||
|
func initializeDatastore() {
|
||||||
|
var err error
|
||||||
|
dialect := viper.GetString("datastore.dialect")
|
||||||
|
storage.StorageEngine, err = storage.CreateDatastore(dialect)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("Exception while creating datastore"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConfig() {
|
func parseConfig() {
|
||||||
|
|
@ -58,7 +70,6 @@ func parseConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runMigrations() {
|
func runMigrations() {
|
||||||
log.Println("Going to run migrations")
|
|
||||||
storage.StorageEngine.GetDatastore().AutoMigrate(
|
storage.StorageEngine.GetDatastore().AutoMigrate(
|
||||||
&models.Component{},
|
&models.Component{},
|
||||||
&models.Account{},
|
&models.Account{},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user