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,5 +1,18 @@
|
||||
// Package config provides NTP Pool specific
|
||||
// configuration tools.
|
||||
// Package config provides environment-based configuration management for NTP Pool services.
|
||||
//
|
||||
// This package handles configuration loading from environment variables and provides
|
||||
// utilities for constructing URLs for web and management interfaces. It supports
|
||||
// deployment-specific settings including hostname configuration, TLS settings,
|
||||
// and deployment modes.
|
||||
//
|
||||
// Configuration is loaded automatically from environment variables:
|
||||
// - deployment_mode: The deployment environment (devel, production, etc.)
|
||||
// - manage_hostname: Hostname for management interface
|
||||
// - web_hostname: Comma-separated list of web hostnames (first is primary)
|
||||
// - manage_tls: Enable TLS for management interface (yes, no, true, false)
|
||||
// - web_tls: Enable TLS for web interface (yes, no, true, false)
|
||||
//
|
||||
// The package includes code generation for accessor methods using the accessory tool.
|
||||
package config
|
||||
|
||||
import (
|
||||
@@ -13,6 +26,9 @@ import (
|
||||
|
||||
//go:generate go tool github.com/masaushi/accessory -type Config
|
||||
|
||||
// Config holds environment-based configuration for NTP Pool services.
|
||||
// It manages hostnames, TLS settings, and deployment modes loaded from
|
||||
// environment variables. The struct includes code-generated accessor methods.
|
||||
type Config struct {
|
||||
deploymentMode string `accessor:"getter"`
|
||||
|
||||
@@ -26,6 +42,16 @@ type Config struct {
|
||||
valid bool `accessor:"getter"`
|
||||
}
|
||||
|
||||
// New creates a new Config instance by loading configuration from environment variables.
|
||||
// It automatically parses hostnames, TLS settings, and deployment mode from the environment.
|
||||
// The configuration is considered valid if at least one web hostname is provided.
|
||||
//
|
||||
// Environment variables used:
|
||||
// - deployment_mode: Deployment environment identifier
|
||||
// - manage_hostname: Management interface hostname
|
||||
// - web_hostname: Comma-separated web hostnames (first becomes primary)
|
||||
// - manage_tls: Management interface TLS setting
|
||||
// - web_tls: Web interface TLS setting
|
||||
func New() *Config {
|
||||
c := Config{}
|
||||
c.deploymentMode = os.Getenv("deployment_mode")
|
||||
@@ -46,10 +72,26 @@ func New() *Config {
|
||||
return &c
|
||||
}
|
||||
|
||||
// WebURL constructs a complete URL for the web interface using the primary web hostname.
|
||||
// It automatically selects HTTP or HTTPS based on the web_tls configuration setting.
|
||||
//
|
||||
// Parameters:
|
||||
// - path: URL path component (should start with "/")
|
||||
// - query: Optional URL query parameters (can be nil)
|
||||
//
|
||||
// Returns a complete URL string suitable for web interface requests.
|
||||
func (c *Config) WebURL(path string, query *url.Values) string {
|
||||
return baseURL(c.webHostname, c.webTLS, path, query)
|
||||
}
|
||||
|
||||
// ManageURL constructs a complete URL for the management interface using the management hostname.
|
||||
// It automatically selects HTTP or HTTPS based on the manage_tls configuration setting.
|
||||
//
|
||||
// Parameters:
|
||||
// - path: URL path component (should start with "/")
|
||||
// - query: Optional URL query parameters (can be nil)
|
||||
//
|
||||
// Returns a complete URL string suitable for management interface requests.
|
||||
func (c *Config) ManageURL(path string, query *url.Values) string {
|
||||
return baseURL(c.manageHostname, c.webTLS, path, query)
|
||||
}
|
||||
|
@@ -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