How skssmd/golang-gin_starter works
Main Components
• Auth Component:
• Contains files like Controlers.go, googleauth.go, methods.go, middlewares.go, models.go, routes.go, and services.go.
• Handles user sign-up, login, JWT token creation/validation, role verification, and Google authentication.
• Control Panel:
• Located in the “controlPanel” directory (with controlPanel/process.go and controlPanel/routes.go).
• Exposes administrative endpoints that allow CRUD operations and advanced queries on registered data models.
• Subscription Module:
• Includes subscription/controllers.go, models.go, routes.go, services.go, and webhook_handler.go.
• Designed to manage subscription services and integrates with the Stripe payment processing.
• Base & Initial Setup:
• “base” holds base executables, and “initials” contains connectToDb.go and loadEndVariables.go – these are used for bootstrapping the database connection and initializing environment variables.
• Entry Point and Configuration:
• main.go orchestrates the overall service startup.
• .env and go.mod provide configuration and dependency management.
• Database:
• There is an integrated database file (database.db), which may be used when opting for SQLite or could be easily swapped for PostgreSQL, as mentioned in the README.
Interactions and Data Flow
• The starting point is the main.go file, which bootstraps the application by initializing database connections (using code from initials/ directory), loading environment variables, and setting up routes.
• The Auth module uses middleware functions (LoginRequired, RequireVerification, RequireAdmin, RequireSuperuser) to secure endpoints; these are invoked on specific routes defined in auth/routes.go.
• The Control Panel module registers models (from the Auth module and other domain-specific models) and exposes RESTful endpoints along with advanced query capabilities for administrative operations.
• The Subscription module encapsulates payment flows, and its routes are exposed as part of the overall API.
• There is a clear separation of concerns: each feature (authentication, subscription, admin control panel) lives in its own package, with shared database connectivity and configuration setup defined in initials and environment files.
Architectural Patterns and Design Principles
• Modularity and Separation of Concerns: Each major functionality is encapsulated in its own directory/package (auth, controlPanel, subscription).
• Middleware Pattern: The use of authentication and authorization middlewares provides fine-grained control over API accessibility.
• RESTful API Design: Endpoints for control panel, authentication, and subscriptions follow a REST-like structure.
• Environment-driven Configuration: The usage of .env and environment variables (e.g., SECRET, VERIFICATION) facilitates flexible configuration.
• Extensibility: For instance, the control panel allows new models to be registered easily, and the advanced query syntax provides a versatile query mechanism.
Technologies, Frameworks, and Libraries
• Gin Framework: The foundation for routing and handling HTTP requests.
• JWT for authentication and token management.
• Stripe: For payment and subscription services.
• Database (PostgreSQL or SQLite): Managed through standard Go database connectivity practices.
• Go modules for dependency management.