![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
github.com/jujili/clock
clock 中的 realClock
和 simulator
结构体,都实现了 clock.Clock
接口。需要实际时间时,使用前者;需要人为地操纵时间的场合(比如:测试)中,使用后者。
在 time
和 context
标准库中,有一些函数和方法依赖于系统的当前时间。Clock
接口就是由这些内容组成。
clock 模块分为真实与虚拟的两个部分。真实的部分是以 time 和 context 标准库为基础,封装成了 Clock 接口。 虚拟部分也实现了 Clock 接口,只是这一部分可以人为的操控时间的改变。
在命令行中输入以下内容,可以获取到最新版
go get -u github.com/jujili/clock
c := clock.NewRealClock()
// 输出操作系统的当前时间
fmt.Println(c.Now())
真实的 Clock 就是把 time
和 context
标准库中的相关函数,封装成了 realClock
的方法。
now,_ := time.Parse("06-01-02", "20-01-26")
c := clock.NewSimulator(now)
// 输出: 2020-01-26 00:00:00 +0000 UTC
fmt.Println(c.Now())
*Simulator
和 contextSim
虽然是模拟的。但是,实现了与 time
和 context
标准库中同名函数一样的行为。
在 clock 目录下,输入
$ mockgen -source=./interface.go -destination=./clock_mock_test.go -package=clock
$
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.