Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit d48e258

Browse files
authored
chore: support go1.17 (#11)
1 parent 8e4051e commit d48e258

File tree

5 files changed

+45
-22
lines changed

5 files changed

+45
-22
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
go-version: [ 1.15, 1.16 ]
13+
go-version: [ 1.16, 1.17 ]
1414
runs-on: ubuntu-latest
1515
env:
16-
GOLANGCI_LINT_VERSION: v1.41.1
16+
GOLANGCI_LINT_VERSION: v1.42.0
1717

1818
steps:
1919
- name: Install Go

time.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
11
// Package timex provides a fast wall clock source.
22
package timex
33

4-
import (
5-
"time"
6-
// Required in order to import walltime.
7-
_ "unsafe"
8-
)
9-
10-
//go:linkname walltime runtime.walltime
11-
func walltime() (int64, int32)
12-
13-
// Now returns the current time in nanoseconds.
14-
func Now() int64 {
15-
sec, nsec := walltime()
16-
return sec*1000000000 + int64(nsec)
17-
}
4+
import "time"
185

196
// Since is analogous to https://golang.org/pkg/time/#Since.
207
func Since(s int64) time.Duration {
218
return time.Duration(Now() - s)
229
}
23-
24-
// Unix returns the current time in seconds.
25-
func Unix() int64 {
26-
sec, _ := walltime()
27-
return sec
28-
}

time_now.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build !go1.17
2+
// +build !go1.17
3+
4+
package timex
5+
6+
import _ "unsafe" // for go:linkname
7+
8+
//go:linkname walltime runtime.walltime
9+
func walltime() (int64, int32)
10+
11+
// Now returns the current time in nanoseconds.
12+
func Now() int64 {
13+
sec, nsec := walltime()
14+
return sec*1000000000 + int64(nsec)
15+
}
16+
17+
// Unix returns the current time in seconds.
18+
func Unix() int64 {
19+
sec, _ := walltime()
20+
return sec
21+
}

time.s renamed to time_now.s

File renamed without changes.

time_now_go1_17.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build go1.17
2+
// +build go1.17
3+
4+
package timex
5+
6+
import _ "unsafe" // for go:linkname
7+
8+
//go:linkname now time.now
9+
func now() (int64, int32, int64)
10+
11+
// Now returns the current time in nanoseconds.
12+
func Now() int64 {
13+
sec, nsec, _ := now()
14+
return sec*1000000000 + int64(nsec)
15+
}
16+
17+
// Unix returns the current time in seconds.
18+
func Unix() int64 {
19+
sec, _, _ := now()
20+
return sec
21+
}

0 commit comments

Comments
 (0)