types

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2025 License: BSD-3-Clause-Clear Imports: 3 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogScoreAttributes

type LogScoreAttributes struct {
	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"` // Source log server ID for traceability
	FromSSID int `json:"from_ss_id,omitempty"` // Source scoring system ID for traceability
}

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.

func (*LogScoreAttributes) Scan

func (lsa *LogScoreAttributes) Scan(value any) error

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 (*LogScoreAttributes) String

func (lsa *LogScoreAttributes) String() string

String returns a JSON representation of the LogScoreAttributes for logging and debugging. Returns an empty string if JSON marshaling fails.

func (*LogScoreAttributes) Value

func (lsa *LogScoreAttributes) Value() (driver.Value, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL