How elrojo/go-vault works
Main Components
• API Service: The core service entry point is the Go application (main.go) which initializes the API server. The “api” folder contains handler logic (api.go, vault_handlers.go) that sets up endpoints (such as /vault/init and /vault/secret).
• Controllers: Organized under the “controllers/vault” directory, these files (vault.go, vault_config.go, vault_types.go) encapsulate core business logic for handling vault operations like initialization, configuration, and secret mapping.
• Utility Layer: Located in “internal/utility”, this layer contains helper functions (logger, pwgen, validate_request_fields, etc.) for tasks such as logging, secure password generation, and request validation.
• External Vault Service: The system interacts with HashiCorp Vault (not part of this project’s codebase but a key external dependency). The README describes how to authenticate and communicate with Vault via its HTTP API.
• Infrastructure & CI/CD: The Dockerfile and docker-compose.yml outline containerization and orchestration for both the API and Vault. GitHub workflows (in .github/workflows) define CI/CD pipelines for PR and push events.
Relationships and Interactions
• The API Layer (main.go → api handlers) receives HTTP requests.
• Controllers process business logic and delegate calls to the Vault client (via the vault-client-go package) and manage the vault’s “flat-file” configuration.
• Utility functions support both controllers and API by providing logging, request validation, and secure password generation.
• The Docker configuration ensures the API server runs in a containerized environment and communicates with a separate Vault container instance.
• GitHub workflows trigger builds, tests, and deployments as code is pushed or pull requests are made.
Architectural Patterns and Technologies
• Separation of Concerns: Clear division between API handlers, business logic (controllers), and supporting utilities.
• Dependency Injection / Interface Abstraction: As shown in the vault_test.go, mocking and dependency injection are used to facilitate testing.
• Containerization: Docker and docker-compose facilitate consistent deployment environments.
• External Service Integration: Use of the vault-client-go package ensures smooth CRUD operations with HashiCorp Vault.
• RESTful API Design: The API documentation shows well-structured endpoints and standardized request/response formats.