main.go 🛠️
Purpose
The main.go file serves as the entry point of the Dynamic Notification System application. It orchestrates the initialization of configurations, plugins, the scheduler, and the HTTP server.
Key Functions 🔑
1. Configuration Loading
- Purpose: Loads the application's configuration settings from the config.yamlfile.
- Implementation:
- Function: config.LoadConfig
- Steps:- Reads the config.yamlfile from the root directory.
- Validates and parses the configuration into a structured Configobject.
 
- Reads the 
- Example:
2. Plugin Loading
- Purpose: Dynamically loads plugins that define notification channels.
- Implementation:
- Function: plugins.LoadPlugins
- Steps:- Scans the plugins/directory for.sofiles.
- Loads and initializes each plugin dynamically.
 
- Scans the 
- Example:
3. Scheduler Initialization
- Purpose: Sets up the job scheduler, responsible for executing tasks based on cron expressions.
- Implementation:
- Function: scheduler.Initialize
- Steps:- Establishes a database connection.
- Loads jobs from the database into the scheduler.
- Starts the cron scheduler.
 
- Example:
4. HTTP Server Setup
- Purpose: Starts the HTTP server to handle API requests for managing notifications and jobs.
- Implementation:
- Library: Gorilla Mux
- Steps:- Creates a new router.
- Defines routes for job management endpoints (/jobs).
- Starts the server on the configured port (default: 8080).
 
- Example:
Example Flow 🔄
- Application Start:
- Reads config.yaml.
- Loads plugins from the plugins/directory.
- Initializes the scheduler and loads jobs.
- 
Starts the HTTP server. 
- 
Incoming API Requests: 
- Routes are handled via the Gorilla Mux router.
- Jobs are added, retrieved, or managed based on the API calls.
Error Handling ⚠️
- Logs detailed error messages and exits gracefully if critical components fail to initialize.
- Example:
This documentation provides a high-level overview and examples for understanding and extending the functionality of the main.go file. Happy coding! 🚀