Package monoton is a highly scalable, single/multi node, human-readable, predictable and incremental unique id generator The monoton package provides sequences based on the monotonic time which represents the absolute elapsed wall-clock time since some arbitrary, fixed point in the past. It isn't affected by changes in the system time-of-day clock. Initial time value opens space for the time value by subtracting the given value from the time sequence. The monoton package converts all sequences into Base62 format. And Base62 only uses ASCII alpha-numeric chars to represent data which makes it easy to read, predict the order by a human eye. The total byte size is fixed to 16 bytes for all sequencers. And at least one byte is reserved to nodes. The monoton package can be used on single/multiple nodes without the need for machine coordination. It uses configured node identifier to generate ids by attaching the node identifier to the end of the sequences. The package comes with three pre-configured sequencers and Sequencer interface to allow new sequencers. The monoton package currently comes with Nanosecond, Millisecond and Second sequencers. And it uses Millisecond sequencer by default. For each sequencer, the byte orders are as following: The sequencers can be extended for any other time format, sequence format by implementing the monoton/sequncer.Sequencer interface. Example using Singleton
Package clocks provides the Clock interface and a default implementations: the defaultClock implementation (returned by DefaultClock()) defaultClock should always be used within production, as it is a trivial wrapper around the real clock-derived functions in the time package of the Go standard library. In the fake subpackage there is a fake.Clock (created by fake.NewClock()) fake.Clock is present for use in tests, with some helpers for useful synchronization, such as AwaitSleepers() which lets a test goroutine block until some number of other goroutines are sleeping. See the documentation on the individual methods of fake.Clock for more specific documentation. The offset subpackage contains an offset.Clock type which simply adds a constant offset to any interactions with an absolute time. This type is most useful for simulating clock-skew/unsynchronization in combination with the fake-clock.
2fa is a two-factor authentication agent. Usage: “2fa -add name” adds a new key to the 2fa keychain with the given name. It prints a prompt to standard error and reads a two-factor key from standard input. Two-factor keys are short case-insensitive strings of letters A-Z and digits 2-7. By default the new key generates time-based (TOTP) authentication codes; the -hotp flag makes the new key generate counter-based (HOTP) codes instead. By default the new key generates 6-digit codes; the -7 and -8 flags select 7- and 8-digit codes instead. “2fa -list” lists the names of all the keys in the keychain. “2fa name” prints a two-factor authentication code from the key with the given name. If “-clip” is specified, 2fa also copies the code to the system clipboard. With no arguments, 2fa prints two-factor authentication codes from all known time-based keys. The default time-based authentication codes are derived from a hash of the key and the current time, so it is important that the system clock have at least one-minute accuracy. The keychain is stored unencrypted in the text file $HOME/.2fa. During GitHub 2FA setup, at the “Scan this barcode with your app” step, click the “enter this text code instead” link. A window pops up showing “your two-factor secret,” a short string of letters and digits. Add it to 2fa under the name github, typing the secret at the prompt: Then whenever GitHub prompts for a 2FA code, run 2fa to obtain one: Or to type less:
Package clock provides an interface for obtaining the current time and sleeping.
A ballclock represents a set of 3 rungs The first rung represents minutes The second 5 minute increments and the last, 1 hour increments In the general case, the state of a ball clock can be defined as a polynomial using a variable base (10/1, 60/5, 12/1) or (10, 2, 12) We can defined a function t(x1, x2, x3) where t is time in minutes, x1 is minutes, x2 is sets of minutes and x3 is hours. as t(x1, x2, x3) = x1 + 5*x2 + 60*x3 where x1 ∈ [0..9], x2 ∈ [0..11], x3 ∈ [0..11]
Package clock makes the functionality of the time package injectable in unit tests and other code. It also provides a few convenient goodies, that reduce the work needed to write unit tests. To benefit from this package, instead of calling time.Now directly, pass clock.Real (type: clock.Clock) to your functions or structs, and call its Now methods: Now, Sleep etc. Then in unit tests, pass a clock that you control, created with clock.NewController.
Package clock provides an abstraction for system time that enables testing of time-sensitive code. Where you'd use time.Now, instead use clk.Now where clk is an instance of Clock. When running your code in production, pass it a Clock given by Default() and when you're running it in your tests, pass it an instance of Clock from NewFake(). When you do that, you can use FakeClock's Add and Set methods to control how time behaves in your code making them more reliable while also expanding the space of problems you can test. This code intentionally does not attempt to provide an abstraction over time.Ticker and time.Timer because Go does not have the runtime or API hooks available to do reliably. See https://github.com/golang/go/issues/8869 Be sure to test Time equality with time.Time#Equal, not ==.
Package clock is a low consumption, low latency support for frequent updates of large capacity timing manager: 基本处理逻辑: 使用方式,参见示例代码。
package clock provides methods for determining the corresponding time in other timezones in the world.