-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1862814
commit 3bafd41
Showing
8 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Go package | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.19' | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
# Time Provider | ||
# NTP Time Provider | ||
|
||
基于NTP的TimeProvider | ||
# 一、这是什么 | ||
|
||
基于NTP的TimeProvider实现,Storage的具体实现可以引入这个库来实现GetTime方法,让分布式系统中的各个角色使用统一的NTP时间源。 | ||
|
||
# 二、安装依赖 | ||
|
||
```bash | ||
go get -u github.com/storage-lock/go-ntp-time-provider | ||
``` | ||
|
||
# 三、API示例 | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/storage-lock/go-events" | ||
ntp_time_provider "github.com/storage-lock/go-ntp-time-provider" | ||
) | ||
|
||
func main() { | ||
|
||
event := events.NewEvent("test") | ||
timeProvider := ntp_time_provider.NewNTPTimeProvider(event) | ||
time, err := timeProvider.GetTime(context.Background()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(time) | ||
// Output: | ||
// 2023-08-07 01:36:18.29416265 +0800 CST m=-1.335806449 | ||
|
||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package storage | ||
package ntp_time_provider | ||
|
||
// time provider | ||
const ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package storage | ||
package ntp_time_provider | ||
|
||
import "errors" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/storage-lock/go-events" | ||
ntp_time_provider "github.com/storage-lock/go-ntp-time-provider" | ||
) | ||
|
||
func main() { | ||
|
||
event := events.NewEvent("test") | ||
timeProvider := ntp_time_provider.NewNTPTimeProvider(event) | ||
time, err := timeProvider.GetTime(context.Background()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(time) | ||
// Output: | ||
// 2023-08-07 01:36:18.29416265 +0800 CST m=-1.335806449 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package storage | ||
package ntp_time_provider | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package storage | ||
package ntp_time_provider | ||
|
||
import ( | ||
"context" | ||
|