{"id":19865836,"url":"https://github.com/beevik/ntp","last_synced_at":"2025-05-14T08:06:22.289Z","repository":{"id":9378711,"uuid":"11237307","full_name":"beevik/ntp","owner":"beevik","description":"a simple ntp client package for go","archived":false,"fork":false,"pushed_at":"2024-07-16T06:26:06.000Z","size":219,"stargazers_count":588,"open_issues_count":0,"forks_count":86,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-04-09T02:17:24.871Z","etag":null,"topics":["go","ntp","ntp-client","ntp-protocol","sntp","time"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beevik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-07T17:48:24.000Z","updated_at":"2025-04-05T09:48:55.000Z","dependencies_parsed_at":"2024-06-03T04:28:40.723Z","dependency_job_id":"4ce2375f-5c06-455f-b219-921ce21466c5","html_url":"https://github.com/beevik/ntp","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beevik%2Fntp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beevik%2Fntp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beevik%2Fntp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beevik%2Fntp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beevik","download_url":"https://codeload.github.com/beevik/ntp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101615,"owners_count":22014909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","ntp","ntp-client","ntp-protocol","sntp","time"],"created_at":"2024-11-12T15:24:18.874Z","updated_at":"2025-05-14T08:06:17.257Z","avatar_url":"https://github.com/beevik.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"[![GoDoc](https://godoc.org/github.com/beevik/ntp?status.svg)](https://godoc.org/github.com/beevik/ntp)\r\n[![Go](https://github.com/beevik/ntp/actions/workflows/go.yml/badge.svg)](https://github.com/beevik/ntp/actions/workflows/go.yml)\r\n\r\nntp\r\n===\r\n\r\nThe ntp package is an implementation of a Simple NTP (SNTP) client based on\r\n[RFC 5905](https://tools.ietf.org/html/rfc5905). It allows you to connect to\r\na remote NTP server and request information about the current time.\r\n\r\n\r\n## Querying the current time\r\n\r\nIf all you care about is the current time according to a remote NTP server,\r\nsimply use the `Time` function:\r\n```go\r\ntime, err := ntp.Time(\"0.beevik-ntp.pool.ntp.org\")\r\n```\r\n\r\n\r\n## Querying time synchronization data\r\n\r\nTo obtain the current time as well as some additional synchronization data,\r\nuse the [`Query`](https://godoc.org/github.com/beevik/ntp#Query) function:\r\n```go\r\nresponse, err := ntp.Query(\"0.beevik-ntp.pool.ntp.org\")\r\ntime := time.Now().Add(response.ClockOffset)\r\n```\r\n\r\nThe [`Response`](https://godoc.org/github.com/beevik/ntp#Response) structure\r\nreturned by `Query` includes the following information:\r\n* `ClockOffset`: The estimated offset of the local system clock relative to\r\n  the server's clock. For a more accurate time reading, you may add this\r\n  offset to any subsequent system clock reading.\r\n* `Time`: The time the server transmitted its response, according to its own\r\n  clock.\r\n* `RTT`: An estimate of the round-trip-time delay between the client and the\r\n  server.\r\n* `Precision`: The precision of the server's clock reading.\r\n* `Stratum`: The server's stratum, which indicates the number of hops from the\r\n  server to the reference clock. A stratum 1 server is directly attached to\r\n  the reference clock. If the stratum is zero, the server has responded with\r\n  the \"kiss of death\" and you should examine the `KissCode`.\r\n* `ReferenceID`: A unique identifier for the consulted reference clock.\r\n* `ReferenceTime`: The time at which the server last updated its local clock setting.\r\n* `RootDelay`: The server's aggregate round-trip-time delay to the stratum 1 server.\r\n* `RootDispersion`: The server's estimated maximum measurement error relative\r\n  to the reference clock.\r\n* `RootDistance`: An estimate of the root synchronization distance between the\r\n  client and the stratum 1 server.\r\n* `Leap`: The leap second indicator, indicating whether a second should be\r\n  added to or removed from the current month's last minute.\r\n* `MinError`: A lower bound on the clock error between the client and the\r\n  server.\r\n* `KissCode`: A 4-character string describing the reason for a \"kiss of death\"\r\n  response (stratum=0).\r\n* `Poll`: The maximum polling interval between successive messages to the\r\n  server.\r\n\r\nThe `Response` structure's [`Validate`](https://godoc.org/github.com/beevik/ntp#Response.Validate)\r\nfunction performs additional sanity checks to determine whether the response\r\nis suitable for time synchronization purposes.\r\n```go\r\nerr := response.Validate()\r\nif err == nil {\r\n    // response data is suitable for synchronization purposes\r\n}\r\n```\r\n\r\nIf you wish to customize the behavior of the NTP query, use the\r\n[`QueryWithOptions`](https://godoc.org/github.com/beevik/ntp#QueryWithOptions)\r\nfunction:\r\n```go\r\noptions := ntp.QueryOptions{ Timeout: 30*time.Second, TTL: 5 }\r\nresponse, err := ntp.QueryWithOptions(\"0.beevik-ntp.pool.ntp.org\", options)\r\ntime := time.Now().Add(response.ClockOffset)\r\n```\r\n\r\nConfigurable [`QueryOptions`](https://godoc.org/github.com/beevik/ntp#QueryOptions)\r\ninclude:\r\n* `Timeout`: How long to wait before giving up on a response from the NTP\r\n  server.\r\n* `Version`: Which version of the NTP protocol to use (2, 3 or 4).\r\n* `TTL`: The maximum number of IP hops before the request packet is discarded.\r\n* `Auth`: The symmetric authentication key and algorithm used by the server to\r\n  authenticate the query. The same information is used by the client to\r\n  authenticate the server's response.\r\n* `Extensions`: Extensions may be added to modify NTP queries before they are\r\n\ttransmitted and to process NTP responses after they arrive.\r\n* `Dialer`: A custom network connection \"dialer\" function used to override the\r\n  default UDP dialer function.\r\n\r\n\r\n## Using the NTP pool\r\n\r\nThe NTP pool is a shared resource provided by the [NTP Pool\r\nProject](https://www.pool.ntp.org/en/) and used by people and services all\r\nover the world. To prevent it from becoming overloaded, please avoid querying\r\nthe standard `pool.ntp.org` zone names in your applications. Instead, consider\r\nrequesting your own [vendor zone](http://www.pool.ntp.org/en/vendors.html) or\r\n[joining the pool](http://www.pool.ntp.org/join.html).\r\n\r\n\r\n## Network Time Security (NTS)\r\n\r\nNetwork Time Security (NTS) is a recent enhancement of NTP, designed to add\r\nbetter authentication and message integrity to the protocol. It is defined by\r\n[RFC 8915](https://tools.ietf.org/html/rfc8915). If you wish to use NTS, see\r\nthe [nts package](https://github.com/beevik/nts). (The nts package is\r\nimplemented as an extension to this package.)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeevik%2Fntp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeevik%2Fntp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeevik%2Fntp/lists"}