ntp

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAvailableServer = errors.New("no available NTP server found")
View Source
var ErrNotReachable = errors.New("failed to reach NTP server")

Functions

func GetBuiltinServers

func GetBuiltinServers() []string

GetBuiltinServers 获取内置的 NTP 服务器列表

func Now

func Now(address ...string) (time.Time, error)

func RestartNTPService

func RestartNTPService() error

RestartNTPService 重启 NTP 服务

func SetSystemNTPServers

func SetSystemNTPServers(servers []string) error

SetSystemNTPServers 设置系统 NTP 服务器

func UpdateSystemTime

func UpdateSystemTime(t time.Time) error

func UpdateSystemTimeZone

func UpdateSystemTimeZone(tz string) error

Types

type NTPServiceType

type NTPServiceType string

NTPServiceType 表示系统使用的 NTP 服务类型

const (
	NTPServiceTimesyncd NTPServiceType = "timesyncd" // systemd-timesyncd (Debian/Ubuntu)
	NTPServiceChrony    NTPServiceType = "chrony"    // chrony (RHEL/CentOS/Rocky)
	NTPServiceUnknown   NTPServiceType = "unknown"   // 未知或不支持
)

func DetectNTPService

func DetectNTPService() NTPServiceType

DetectNTPService 检测系统使用的 NTP 服务类型

type SystemNTPConfig

type SystemNTPConfig struct {
	ServiceType NTPServiceType `json:"service_type"` // 服务类型
	Servers     []string       `json:"servers"`      // NTP 服务器列表
}

SystemNTPConfig 系统 NTP 配置信息

func GetSystemNTPConfig

func GetSystemNTPConfig() (*SystemNTPConfig, error)

GetSystemNTPConfig 获取系统 NTP 配置

Jump to

Keyboard shortcuts

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