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,17 @@
|
||||
// Package types provides shared data structures for the NTP Pool project.
|
||||
//
|
||||
// This package contains common types used across different NTP Pool services
|
||||
// for data exchange, logging, and database operations. The types are designed
|
||||
// to support JSON serialization for API responses and SQL database storage
|
||||
// with automatic marshaling/unmarshaling.
|
||||
//
|
||||
// Current types include:
|
||||
// - LogScoreAttributes: NTP server scoring metadata for monitoring and analysis
|
||||
//
|
||||
// All types implement appropriate interfaces for:
|
||||
// - JSON serialization (json.Marshaler/json.Unmarshaler)
|
||||
// - SQL database storage (database/sql/driver.Valuer/sql.Scanner)
|
||||
// - String representation for logging and debugging
|
||||
package types
|
||||
|
||||
import (
|
||||
@@ -6,17 +20,26 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// LogScoreAttributes contains metadata about NTP server scoring and monitoring results.
|
||||
// This structure captures both NTP protocol-specific information (leap, stratum) and
|
||||
// operational data (errors, warnings, response status) for analysis and alerting.
|
||||
//
|
||||
// The type supports JSON serialization for API responses and database storage
|
||||
// via the database/sql/driver interfaces. Fields use omitempty tags to minimize
|
||||
// JSON payload size when values are at their zero state.
|
||||
type LogScoreAttributes struct {
|
||||
Leap int8 `json:"leap,omitempty"`
|
||||
Stratum int8 `json:"stratum,omitempty"`
|
||||
NoResponse bool `json:"no_response,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Warning string `json:"warning,omitempty"`
|
||||
Leap int8 `json:"leap,omitempty"` // NTP leap indicator (0=no warning, 1=+1s, 2=-1s, 3=unsynchronized)
|
||||
Stratum int8 `json:"stratum,omitempty"` // NTP stratum level (1=primary, 2-15=secondary, 16=unsynchronized)
|
||||
NoResponse bool `json:"no_response,omitempty"` // True if server failed to respond to NTP queries
|
||||
Error string `json:"error,omitempty"` // Error message if scoring failed
|
||||
Warning string `json:"warning,omitempty"` // Warning message for non-fatal issues
|
||||
|
||||
FromLSID int `json:"from_ls_id,omitempty"`
|
||||
FromSSID int `json:"from_ss_id,omitempty"`
|
||||
FromLSID int `json:"from_ls_id,omitempty"` // Source log server ID for traceability
|
||||
FromSSID int `json:"from_ss_id,omitempty"` // Source scoring system ID for traceability
|
||||
}
|
||||
|
||||
// String returns a JSON representation of the LogScoreAttributes for logging and debugging.
|
||||
// Returns an empty string if JSON marshaling fails.
|
||||
func (lsa *LogScoreAttributes) String() string {
|
||||
b, err := json.Marshal(lsa)
|
||||
if err != nil {
|
||||
@@ -25,10 +48,17 @@ func (lsa *LogScoreAttributes) String() string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Value implements the database/sql/driver.Valuer interface for database storage.
|
||||
// It serializes the LogScoreAttributes to JSON for storage in SQL databases.
|
||||
// Returns the JSON bytes or an error if marshaling fails.
|
||||
func (lsa *LogScoreAttributes) Value() (driver.Value, error) {
|
||||
return json.Marshal(lsa)
|
||||
}
|
||||
|
||||
// Scan implements the database/sql.Scanner interface for reading from SQL databases.
|
||||
// It deserializes JSON data from the database back into LogScoreAttributes.
|
||||
// Supports both []byte and string input types, with nil values treated as no-op.
|
||||
// Returns an error if the input type is unsupported or JSON unmarshaling fails.
|
||||
func (lsa *LogScoreAttributes) Scan(value any) error {
|
||||
var source []byte
|
||||
_t := LogScoreAttributes{}
|
||||
|
Reference in New Issue
Block a user