mirror of
https://github.com/go-gitea/gitea
synced 2024-09-18 17:56:03 +00:00
d1353e1f7c
* update code.gitea.io/sdk/gitea v0.13.1 -> v0.13.2 * update github.com/go-swagger/go-swagger v0.25.0 -> v0.26.0 * update github.com/google/uuid v1.1.2 -> v1.2.0 * update github.com/klauspost/compress v1.11.3 -> v1.11.7 * update github.com/lib/pq 083382b7e6fc -> v1.9.0 * update github.com/markbates/goth v1.65.0 -> v1.66.1 * update github.com/mattn/go-sqlite3 v1.14.4 -> v1.14.6 * update github.com/mgechev/revive 246eac737dc7 -> v1.0.3 * update github.com/minio/minio-go/v7 v7.0.6 -> v7.0.7 * update github.com/niklasfasching/go-org v1.3.2 -> v1.4.0 * update github.com/olivere/elastic/v7 v7.0.21 -> v7.0.22 * update github.com/pquerna/otp v1.2.0 -> v1.3.0 * update github.com/xanzy/go-gitlab v0.39.0 -> v0.42.0 * update github.com/yuin/goldmark v1.2.1 -> v1.3.1
86 lines
2.1 KiB
Go
Vendored
86 lines
2.1 KiB
Go
Vendored
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package core provides support for event based telemetry.
|
|
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"golang.org/x/tools/internal/event/label"
|
|
)
|
|
|
|
// Event holds the information about an event of note that occurred.
|
|
type Event struct {
|
|
at time.Time
|
|
|
|
// As events are often on the stack, storing the first few labels directly
|
|
// in the event can avoid an allocation at all for the very common cases of
|
|
// simple events.
|
|
// The length needs to be large enough to cope with the majority of events
|
|
// but no so large as to cause undue stack pressure.
|
|
// A log message with two values will use 3 labels (one for each value and
|
|
// one for the message itself).
|
|
|
|
static [3]label.Label // inline storage for the first few labels
|
|
dynamic []label.Label // dynamically sized storage for remaining labels
|
|
}
|
|
|
|
// eventLabelMap implements label.Map for a the labels of an Event.
|
|
type eventLabelMap struct {
|
|
event Event
|
|
}
|
|
|
|
func (ev Event) At() time.Time { return ev.at }
|
|
|
|
func (ev Event) Format(f fmt.State, r rune) {
|
|
if !ev.at.IsZero() {
|
|
fmt.Fprint(f, ev.at.Format("2006/01/02 15:04:05 "))
|
|
}
|
|
for index := 0; ev.Valid(index); index++ {
|
|
if l := ev.Label(index); l.Valid() {
|
|
fmt.Fprintf(f, "\n\t%v", l)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (ev Event) Valid(index int) bool {
|
|
return index >= 0 && index < len(ev.static)+len(ev.dynamic)
|
|
}
|
|
|
|
func (ev Event) Label(index int) label.Label {
|
|
if index < len(ev.static) {
|
|
return ev.static[index]
|
|
}
|
|
return ev.dynamic[index-len(ev.static)]
|
|
}
|
|
|
|
func (ev Event) Find(key label.Key) label.Label {
|
|
for _, l := range ev.static {
|
|
if l.Key() == key {
|
|
return l
|
|
}
|
|
}
|
|
for _, l := range ev.dynamic {
|
|
if l.Key() == key {
|
|
return l
|
|
}
|
|
}
|
|
return label.Label{}
|
|
}
|
|
|
|
func MakeEvent(static [3]label.Label, labels []label.Label) Event {
|
|
return Event{
|
|
static: static,
|
|
dynamic: labels,
|
|
}
|
|
}
|
|
|
|
// CloneEvent event returns a copy of the event with the time adjusted to at.
|
|
func CloneEvent(ev Event, at time.Time) Event {
|
|
ev.at = at
|
|
return ev
|
|
}
|