Add comprehensive godoc documentation to all packages
- Add package-level documentation with usage examples and architecture details - Document all public types, functions, and methods following godoc conventions - Remove unused logger.Error type and NewError function - Apply consistent documentation style across all packages Packages updated: - apitls: TLS certificate management with automatic renewal - config: Environment-based configuration system - config/depenv: Deployment environment handling - ekko: Enhanced Echo web framework wrapper - kafka: Kafka client wrapper with TLS support - logger: Structured logging with OpenTelemetry integration - tracing: OpenTelemetry distributed tracing setup - types: Shared data structures for NTP Pool project - xff/fastlyxff: Fastly CDN IP range management All tests pass after documentation changes.
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
// Package depenv provides deployment environment management for NTP Pool services.
|
||||
//
|
||||
// This package handles different deployment environments (development, test, production)
|
||||
// and provides environment-specific configuration including API endpoints, management URLs,
|
||||
// and monitoring domains. It supports string-based environment identification and
|
||||
// automatic URL construction for various service endpoints.
|
||||
//
|
||||
// The package defines three main deployment environments:
|
||||
// - DeployDevel: Development environment with dev-specific endpoints
|
||||
// - DeployTest: Test/beta environment for staging
|
||||
// - DeployProd: Production environment with live endpoints
|
||||
//
|
||||
// Environment detection supports both short and long forms:
|
||||
// - "dev" or "devel" → DeployDevel
|
||||
// - "test" or "beta" → DeployTest
|
||||
// - "prod" → DeployProd
|
||||
package depenv
|
||||
|
||||
import (
|
||||
@@ -24,14 +40,27 @@ var apiServers = map[DeploymentEnvironment]string{
|
||||
// }
|
||||
|
||||
const (
|
||||
// DeployUndefined represents an unrecognized or unset deployment environment.
|
||||
DeployUndefined DeploymentEnvironment = iota
|
||||
// DeployDevel represents the development environment.
|
||||
DeployDevel
|
||||
// DeployTest represents the test/beta environment.
|
||||
DeployTest
|
||||
// DeployProd represents the production environment.
|
||||
DeployProd
|
||||
)
|
||||
|
||||
// DeploymentEnvironment represents a deployment environment type.
|
||||
// It provides methods for environment-specific URL construction and
|
||||
// supports text marshaling/unmarshaling for configuration files.
|
||||
type DeploymentEnvironment uint8
|
||||
|
||||
// DeploymentEnvironmentFromString parses a string into a DeploymentEnvironment.
|
||||
// It supports both short and long forms of environment names:
|
||||
// - "dev" or "devel" → DeployDevel
|
||||
// - "test" or "beta" → DeployTest
|
||||
// - "prod" → DeployProd
|
||||
// - any other value → DeployUndefined
|
||||
func DeploymentEnvironmentFromString(s string) DeploymentEnvironment {
|
||||
switch s {
|
||||
case "devel", "dev":
|
||||
@@ -45,6 +74,8 @@ func DeploymentEnvironmentFromString(s string) DeploymentEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
// String returns the canonical string representation of the deployment environment.
|
||||
// Returns "prod", "test", "devel", or panics for invalid environments.
|
||||
func (d DeploymentEnvironment) String() string {
|
||||
switch d {
|
||||
case DeployProd:
|
||||
@@ -58,6 +89,9 @@ func (d DeploymentEnvironment) String() string {
|
||||
}
|
||||
}
|
||||
|
||||
// APIHost returns the API server URL for this deployment environment.
|
||||
// It first checks the API_HOST environment variable for overrides,
|
||||
// then falls back to the environment-specific default API endpoint.
|
||||
func (d DeploymentEnvironment) APIHost() string {
|
||||
if apiHost := os.Getenv("API_HOST"); apiHost != "" {
|
||||
return apiHost
|
||||
@@ -65,14 +99,26 @@ func (d DeploymentEnvironment) APIHost() string {
|
||||
return apiServers[d]
|
||||
}
|
||||
|
||||
// ManageURL constructs a management interface URL for this deployment environment.
|
||||
// It combines the environment-specific management server base URL with the provided path.
|
||||
//
|
||||
// The path parameter should start with "/" for proper URL construction.
|
||||
func (d DeploymentEnvironment) ManageURL(path string) string {
|
||||
return manageServers[d] + path
|
||||
}
|
||||
|
||||
// MonitorDomain returns the monitoring domain for this deployment environment.
|
||||
// The domain follows the pattern: {environment}.mon.ntppool.dev
|
||||
// For example: "devel.mon.ntppool.dev" for the development environment.
|
||||
func (d DeploymentEnvironment) MonitorDomain() string {
|
||||
return d.String() + ".mon.ntppool.dev"
|
||||
}
|
||||
|
||||
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||
// It allows DeploymentEnvironment to be unmarshaled from configuration files
|
||||
// and other text-based formats. Empty strings are treated as valid (no-op).
|
||||
//
|
||||
// Returns an error if the text represents an invalid deployment environment.
|
||||
func (d *DeploymentEnvironment) UnmarshalText(text []byte) error {
|
||||
s := string(text)
|
||||
if s == "" {
|
||||
|
Reference in New Issue
Block a user