Course Overview
Locked video preview

Watch for free

Create a free account to watch this video.

MVC & Application structure

Configuration and secrets

Here is a summary of the video transcript:

  • Centralized Configuration Management
    The video introduces a structured approach to managing application configuration in a single location. Instead of hardcoding values like host and port, configuration is centralized to improve maintainability and reuse.

  • Environment Variables for Flexibility
    Environment variables are used to configure host, port, environment, and project name. This allows settings to vary across development, testing, and production without modifying source code, and keeps sensitive data out of the codebase.

  • Config Struct and Parsing with env Package
    A configuration struct is created and populated using an external env package. Struct tags define the expected environment variable names, and parsing returns an error if required variables are missing.

  • Global Environment and Project Name Handling
    Environment and project name are exposed with controlled global access and default values. Constants define supported environments (development and production), with development as the fallback if unset.

  • .env File Setup and Loading
    A .env file is created to define exported environment variables such as host, port, environment, and project name. These variables are loaded into the terminal using source .env, since Go does not automatically load them.

  • Derived Configuration Methods
    Methods are added to the config struct to compute derived values, such as a TCP address combining host and port. This encapsulates logic within the configuration layer and prepares the application for server startup.