How guoflight/openfly works
Project Type and Purpose
• Project Type: A backend service (with potential front-end collaboration, as invited) that exposes HTTP APIs to manage nginx configurations.
• Purpose: openfly manages nginx’s Layer 4 proxy settings (load balancing, health checks, etc.) by dynamically generating configuration files stored in etcd. It uses a RESTful API to receive configuration commands (with JWT authentication) and interacts with external systems (nginx and etcd).
File Structure
• Top-Level Directories:
• api: Contains the HTTP server entry point (httpServer.go) and versioned API code (v1/handle.go, v1/jwt.go, etc.). This is your API layer.
• common: Consolidates shared functionalities (e.g., etcd interactions, data structures, nginx logic) so that key operations (like generating nginx configuration snippets) are centralized.
• conf: Houses configuration and constant definitions used throughout the service.
• logger: Provides logging facilities.
• flag, utils: Utility functions and command-line parsing that support the main logic.
• cicd: Contains deployment and build scripts used to build and deploy openfly.
• docs: Versioned documentation (including API specs) that can be referenced for integration.
• main.go: The application entry point that assembles these components.
• Architectural Patterns:
• A clean layering approach where the HTTP API routes (managed in the api package) delegate core operations to modules in common and conf.
• Reuse of common libraries (for etcd operations and nginx configuration generation) that abstract interactions with external systems.