-
Notifications
You must be signed in to change notification settings - Fork 50
3. Project Structure
ekedonald edited this page Jul 19, 2024
·
5 revisions
The project is organized to promote modular development and maintainability. Here’s a concise overview of the main directories and files.
Contains internal application logic and configurations.
- config: Configuration setup.
- models: Database models and migrations.
Houses core packages and utilities.
-
repository: Database repository interfaces and implementations.
- storage: General storage interface.
- postgresql: PostgreSQL-specific storage implementation.
- router: HTTP router setup.
Contains the business logic and services used by the application.
Includes all test files for unit and integration testing.
Utility functions and helpers used throughout the application.
Entry point of the application. It initializes the configuration, connects to the database, sets up the router, and starts the HTTP server.
package main
import (
"fmt"
"log"
"github.com/go-playground/validator/v10"
"github.com/hngprojects/hng_boilerplate_golang_web/internal/config"
"github.com/hngprojects/hng_boilerplate_golang_web/internal/models/migrations"
"github.com/hngprojects/hng_boilerplate_golang_web/pkg/repository/storage"
"github.com/hngprojects/hng_boilerplate_golang_web/pkg/repository/storage/postgresql"
"github.com/hngprojects/hng_boilerplate_golang_web/pkg/router"
"github.com/hngprojects/hng_boilerplate_golang_web/utility"
)
func main() {
logger := utility.NewLogger()
configuration := config.Setup(logger, "./app")
postgresql.ConnectToDatabase(logger, configuration.Database)
validatorRef := validator.New()
db := storage.Connection()
if configuration.Database.Migrate {
migrations.RunAllMigrations(db)
}
r := router.Setup(logger, validatorRef, db, &configuration.App)
utility.LogAndPrint("Server running on port 8080")
log.Fatal(r.Listen(":8080"))
}