Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
CC11001100 committed Aug 6, 2023
1 parent 1862814 commit 3bafd41
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 7 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/golang.yaml
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 ./...
35 changes: 33 additions & 2 deletions README.md
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

}
```

2 changes: 1 addition & 1 deletion actions.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package storage
package ntp_time_provider

// time provider
const (
Expand Down
2 changes: 1 addition & 1 deletion default_ntp_server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package storage
package ntp_time_provider

// DefaultNtpServers 默认的NTP服务器,使用者可以在系统初始化的覆盖掉这个变量来设置默认的NTP服务器
var DefaultNtpServers = []string{
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package storage
package ntp_time_provider

import "errors"

Expand Down
22 changes: 22 additions & 0 deletions examples/main.go
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

}
2 changes: 1 addition & 1 deletion ntp_time_provider.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package storage
package ntp_time_provider

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion ntp_time_provider_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package storage
package ntp_time_provider

import (
"context"
Expand Down

0 comments on commit 3bafd41

Please sign in to comment.