mirror of
https://github.com/go-gitea/gitea
synced 2025-12-05 04:18:27 +00:00
Update Vendor (#16325)
* Add Dependencie Update Script * update gitea.com/lunny/levelqueue * update github.com/PuerkitoBio/goquery * update github.com/alecthomas/chroma * update github.com/blevesearch/bleve/v2 * update github.com/caddyserver/certmagic * update github.com/go-enry/go-enry/v2 * update github.com/go-redis/redis/v8 * update github.com/hashicorp/golang-lru * update github.com/klauspost/compress * update github.com/markbates/goth * update github.com/mholt/archiver/v3 * update github.com/microcosm-cc/bluemonday * update github.com/minio/minio-go/v7 * update github.com/olivere/elastic/v7 * update github.com/xanzy/go-gitlab * update github.com/yuin/goldmark
This commit is contained in:
188
vendor/go.uber.org/zap/zapcore/buffered_write_syncer.go
generated
vendored
Normal file
188
vendor/go.uber.org/zap/zapcore/buffered_write_syncer.go
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
// Copyright (c) 2021 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package zapcore
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
const (
|
||||
// _defaultBufferSize specifies the default size used by Buffer.
|
||||
_defaultBufferSize = 256 * 1024 // 256 kB
|
||||
|
||||
// _defaultFlushInterval specifies the default flush interval for
|
||||
// Buffer.
|
||||
_defaultFlushInterval = 30 * time.Second
|
||||
)
|
||||
|
||||
// A BufferedWriteSyncer is a WriteSyncer that buffers writes in-memory before
|
||||
// flushing them to a wrapped WriteSyncer after reaching some limit, or at some
|
||||
// fixed interval--whichever comes first.
|
||||
//
|
||||
// BufferedWriteSyncer is safe for concurrent use. You don't need to use
|
||||
// zapcore.Lock for WriteSyncers with BufferedWriteSyncer.
|
||||
type BufferedWriteSyncer struct {
|
||||
// WS is the WriteSyncer around which BufferedWriteSyncer will buffer
|
||||
// writes.
|
||||
//
|
||||
// This field is required.
|
||||
WS WriteSyncer
|
||||
|
||||
// Size specifies the maximum amount of data the writer will buffered
|
||||
// before flushing.
|
||||
//
|
||||
// Defaults to 256 kB if unspecified.
|
||||
Size int
|
||||
|
||||
// FlushInterval specifies how often the writer should flush data if
|
||||
// there have been no writes.
|
||||
//
|
||||
// Defaults to 30 seconds if unspecified.
|
||||
FlushInterval time.Duration
|
||||
|
||||
// Clock, if specified, provides control of the source of time for the
|
||||
// writer.
|
||||
//
|
||||
// Defaults to the system clock.
|
||||
Clock Clock
|
||||
|
||||
// unexported fields for state
|
||||
mu sync.Mutex
|
||||
initialized bool // whether initialize() has run
|
||||
writer *bufio.Writer
|
||||
ticker *time.Ticker
|
||||
stop chan struct{} // closed when flushLoop should stop
|
||||
stopped bool // whether Stop() has run
|
||||
done chan struct{} // closed when flushLoop has stopped
|
||||
}
|
||||
|
||||
func (s *BufferedWriteSyncer) initialize() {
|
||||
size := s.Size
|
||||
if size == 0 {
|
||||
size = _defaultBufferSize
|
||||
}
|
||||
|
||||
flushInterval := s.FlushInterval
|
||||
if flushInterval == 0 {
|
||||
flushInterval = _defaultFlushInterval
|
||||
}
|
||||
|
||||
if s.Clock == nil {
|
||||
s.Clock = DefaultClock
|
||||
}
|
||||
|
||||
s.ticker = s.Clock.NewTicker(flushInterval)
|
||||
s.writer = bufio.NewWriterSize(s.WS, size)
|
||||
s.stop = make(chan struct{})
|
||||
s.done = make(chan struct{})
|
||||
s.initialized = true
|
||||
go s.flushLoop()
|
||||
}
|
||||
|
||||
// Write writes log data into buffer syncer directly, multiple Write calls will be batched,
|
||||
// and log data will be flushed to disk when the buffer is full or periodically.
|
||||
func (s *BufferedWriteSyncer) Write(bs []byte) (int, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if !s.initialized {
|
||||
s.initialize()
|
||||
}
|
||||
|
||||
// To avoid partial writes from being flushed, we manually flush the existing buffer if:
|
||||
// * The current write doesn't fit into the buffer fully, and
|
||||
// * The buffer is not empty (since bufio will not split large writes when the buffer is empty)
|
||||
if len(bs) > s.writer.Available() && s.writer.Buffered() > 0 {
|
||||
if err := s.writer.Flush(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
return s.writer.Write(bs)
|
||||
}
|
||||
|
||||
// Sync flushes buffered log data into disk directly.
|
||||
func (s *BufferedWriteSyncer) Sync() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
var err error
|
||||
if s.initialized {
|
||||
err = s.writer.Flush()
|
||||
}
|
||||
|
||||
return multierr.Append(err, s.WS.Sync())
|
||||
}
|
||||
|
||||
// flushLoop flushes the buffer at the configured interval until Stop is
|
||||
// called.
|
||||
func (s *BufferedWriteSyncer) flushLoop() {
|
||||
defer close(s.done)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-s.ticker.C:
|
||||
// we just simply ignore error here
|
||||
// because the underlying bufio writer stores any errors
|
||||
// and we return any error from Sync() as part of the close
|
||||
_ = s.Sync()
|
||||
case <-s.stop:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stop closes the buffer, cleans up background goroutines, and flushes
|
||||
// remaining unwritten data.
|
||||
func (s *BufferedWriteSyncer) Stop() (err error) {
|
||||
var stopped bool
|
||||
|
||||
// Critical section.
|
||||
func() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if !s.initialized {
|
||||
return
|
||||
}
|
||||
|
||||
stopped = s.stopped
|
||||
if stopped {
|
||||
return
|
||||
}
|
||||
s.stopped = true
|
||||
|
||||
s.ticker.Stop()
|
||||
close(s.stop) // tell flushLoop to stop
|
||||
<-s.done // and wait until it has
|
||||
}()
|
||||
|
||||
// Don't call Sync on consecutive Stops.
|
||||
if !stopped {
|
||||
err = s.Sync()
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
50
vendor/go.uber.org/zap/zapcore/clock.go
generated
vendored
Normal file
50
vendor/go.uber.org/zap/zapcore/clock.go
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) 2021 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package zapcore
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// DefaultClock is the default clock used by Zap in operations that require
|
||||
// time. This clock uses the system clock for all operations.
|
||||
var DefaultClock = systemClock{}
|
||||
|
||||
// Clock is a source of time for logged entries.
|
||||
type Clock interface {
|
||||
// Now returns the current local time.
|
||||
Now() time.Time
|
||||
|
||||
// NewTicker returns *time.Ticker that holds a channel
|
||||
// that delivers "ticks" of a clock.
|
||||
NewTicker(time.Duration) *time.Ticker
|
||||
}
|
||||
|
||||
// systemClock implements default Clock that uses system time.
|
||||
type systemClock struct{}
|
||||
|
||||
func (systemClock) Now() time.Time {
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func (systemClock) NewTicker(duration time.Duration) *time.Ticker {
|
||||
return time.NewTicker(duration)
|
||||
}
|
||||
4
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
4
vendor/go.uber.org/zap/zapcore/entry.go
generated
vendored
@@ -208,7 +208,7 @@ func (ce *CheckedEntry) Write(fields ...Field) {
|
||||
// If the entry is dirty, log an internal error; because the
|
||||
// CheckedEntry is being used after it was returned to the pool,
|
||||
// the message may be an amalgamation from multiple call sites.
|
||||
fmt.Fprintf(ce.ErrorOutput, "%v Unsafe CheckedEntry re-use near Entry %+v.\n", time.Now(), ce.Entry)
|
||||
fmt.Fprintf(ce.ErrorOutput, "%v Unsafe CheckedEntry re-use near Entry %+v.\n", ce.Time, ce.Entry)
|
||||
ce.ErrorOutput.Sync()
|
||||
}
|
||||
return
|
||||
@@ -221,7 +221,7 @@ func (ce *CheckedEntry) Write(fields ...Field) {
|
||||
}
|
||||
if ce.ErrorOutput != nil {
|
||||
if err != nil {
|
||||
fmt.Fprintf(ce.ErrorOutput, "%v write error: %v\n", time.Now(), err)
|
||||
fmt.Fprintf(ce.ErrorOutput, "%v write error: %v\n", ce.Time, err)
|
||||
ce.ErrorOutput.Sync()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user