
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
github.com/jychri/timer
timer
is a small package, used by git-in-sync.
Package timer
records Moments
inside of a Timer
.
// Moment marks moments in time.
type Moment struct {
Name string
Time time.Time
Start time.Duration // duration since start
Split time.Duration // duration since last moment
}
// Timer collects Moments.
type Timer struct {
Moments []Moment
}
A Timer
is initialized with a Start Moment
.
// Init initializes a *Timer with a Start Moment.
func Init() *Timer {
ti := new(Timer)
st := Moment{Name: "Start", Time: time.Now()} // start
ti.Moments = append(ti.Moments, st)
return ti
}
When a Moment
is added to the Timer
, its Start
and Split
values are
calculated against the previous Moment
and the Start Moment
.
// Mark marks a moment in time as a Moment and appends t.Moments.
func (ti *Timer) Mark(s string) {
sm := ti.Moments[0] // starting moment
lm := ti.Moments[len(ti.Moments)-1] // last moment
m := Moment{Name: s, Time: time.Now()} // name and time
m.Start = time.Since(sm.Time).Truncate(1000) // duration since start
m.Split = m.Start - lm.Start // duration since last moment
ti.Moments = append(ti.Moments, m) // append Moment
}
You can get information about the last Moment
with Time
and
Split
methods. Get
provides access to a specific Moment
.
// Time returns the elapsed time at the last recorded moment in *Timer.
func (ti *Timer) Time() time.Duration {
lm := ti.Moments[len(ti.Moments)-1] // last moment
return lm.Start
}
// Split returns the split time for the last recorded moment in *Timer.
func (ti *Timer) Split() time.Duration {
lm := ti.Moments[len(ti.Moments)-1] // last moment
return lm.Split
}
// Get returns a Moment and an error value from a *Timer.
func (ti *Timer) Get(s string) (Moment, error) {
for _, m := range ti.Moments {
if m.Name == s {
return m, nil
}
}
var em Moment // empty moment
return em, errors.New("no moment found")
}
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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.