Course Overview
Locked video preview

Watch for free

Create a free account to watch this video.

MVC & Application structure

Testable entrypoint

Here is a summary of the video transcript:

  • Application Entry Point in Go
    The application entry point is placed under the cmd directory, which contains executable binaries. A main package is created to initialize and start the blog application.

  • Main Function Structure
    The main function creates a background context, loads configuration, and calls a separate run function. Errors during initialization or execution cause the application to exit with a non-zero status code.

  • Testable Run Function Design
    The run function accepts context and configuration, returning an error to enable testing. This separation improves testability and ensures the application can be validated in different environments.

  • HTTP Server Setup
    Inside run, a router is initialized and passed to an http.Server instance. The server is configured with an address from the configuration, request handler, read/write timeouts, and a shared base context.

  • Server Execution and Logging
    The server logs a startup message and begins listening using ListenAndServe. The returned error is propagated to allow proper handling at the entry point.

  • Running and Verifying the Application
    The application is executed using go run, sourcing environment variables beforehand. The server starts on localhost:8080, confirming that routing and basic functionality work, though database integration is still pending.

  • Next Steps: Database Integration
    While the blog application runs, it lacks persistent storage. The next step is integrating PostgreSQL and covering related database concepts to fully develop the system.