gбновление зависимостей, рефакторинг кода, чтобы он выглядел как гошный проект

This commit is contained in:
eleksir
2025-04-06 20:22:16 +03:00
parent 00257b8e6c
commit cfb98fc0b3
389 changed files with 18649 additions and 9105 deletions

3
vendor/github.com/cockroachdb/fifo/README.md generated vendored Normal file
View File

@@ -0,0 +1,3 @@
DEPRECATED
Moved to [github.com/cockroachdb/crlib](https://github.com/cockroachdb/crlib/tree/main/fifo)

View File

@@ -26,13 +26,47 @@ type Buffer struct {
}
// SingleTagBuffer returns a Buffer with a single tag.
func SingleTagBuffer(key string, value interface{}) *Buffer {
func SingleTagBuffer(key string, value any) *Buffer {
b := &Buffer{}
b.init(1, 1)
b.tags[0] = Tag{key: key, value: value}
return b
}
// BuildBuffer is used to build a *Buffer that contains an arbitrary number
// of tags. Sample usage:
//
// bld := BuildBuffer()
// bld.Add("a", 1)
// bld.Add("b", 2)
// buf := bld.Finish()
//
// It is equivalent to using SingleTagBuffer() followed by Buffer.Add() calls,
// but avoids allocating each intermediate buffer.
func BuildBuffer() BufferBuilder {
bld := BufferBuilder{b: &Buffer{}}
bld.b.init(0, 0)
return bld
}
// BufferBuilder is returned by BuildBuffer.
type BufferBuilder struct {
b *Buffer
}
// Add a log tag to the buffer. If the key was added already, the value is
// replaced.
func (bld *BufferBuilder) Add(key string, value any) {
bld.b.addOrReplace(key, value)
}
// Finish returns the buffer with the tags that were added to the builder.
func (bld *BufferBuilder) Finish() *Buffer {
b := bld.b
bld.b = nil
return b
}
// Get returns the tags, as a slice. This slice must not be modified.
func (b *Buffer) Get() []Tag {
return b.tags
@@ -55,7 +89,7 @@ func (b *Buffer) GetTag(key string) (Tag, bool) {
// Add returns a new buffer with one more tag. If the tag has the same key as an
// earlier tag, that tag is overwritten.
// The receiver can be nil.
func (b *Buffer) Add(key string, value interface{}) *Buffer {
func (b *Buffer) Add(key string, value any) *Buffer {
if b == nil {
return SingleTagBuffer(key, value)
}
@@ -191,7 +225,7 @@ func (b *Buffer) init(length, capacityHint int) {
}
}
func (b *Buffer) addOrReplace(key string, value interface{}) {
func (b *Buffer) addOrReplace(key string, value any) {
for i := range b.tags {
if b.tags[i].key == key {
b.tags[i].value = value

View File

@@ -21,6 +21,9 @@ type contextLogTagsKey struct{}
// FromContext returns the tags stored in the context (by WithTags, AddTag, or
// AddTags).
func FromContext(ctx context.Context) *Buffer {
if fromContextFn != nil {
return fromContextFn(ctx)
}
val := ctx.Value(contextLogTagsKey{})
if val == nil {
return nil
@@ -31,6 +34,9 @@ func FromContext(ctx context.Context) *Buffer {
// WithTags returns a context with the given tags. Any existing tags are
// ignored.
func WithTags(ctx context.Context, tags *Buffer) context.Context {
if withTagsFn != nil {
return withTagsFn(ctx, tags)
}
return context.WithValue(ctx, contextLogTagsKey{}, tags)
}
@@ -63,3 +69,19 @@ func AddTags(ctx context.Context, tags *Buffer) context.Context {
}
return WithTags(ctx, newB)
}
// OverrideContextFuncs can be used to override the implementation of
// FromContext and WithTags. This is useful if we have a more efficient
// implementation of context-associated values.
//
// Must be called before WithTags or FromContext are called.
func OverrideContextFuncs(
fromContext func(ctx context.Context) *Buffer,
withTags func(ctx context.Context, tags *Buffer) context.Context,
) {
fromContextFn = fromContext
withTagsFn = withTags
}
var fromContextFn func(ctx context.Context) *Buffer
var withTagsFn func(ctx context.Context, tags *Buffer) context.Context

View File

@@ -88,23 +88,20 @@ func mkdirAllAndSyncParents(fs vfs.FS, destDir string) (vfs.File, error) {
// Collect paths for all directories between destDir (excluded) and its
// closest existing ancestor (included).
var parentPaths []string
foundExistingAncestor := false
for parentPath := fs.PathDir(destDir); parentPath != "."; parentPath = fs.PathDir(parentPath) {
for parentPath := fs.PathDir(destDir); ; parentPath = fs.PathDir(parentPath) {
parentPaths = append(parentPaths, parentPath)
if fs.PathDir(parentPath) == parentPath {
break
}
_, err := fs.Stat(parentPath)
if err == nil {
// Exit loop at the closest existing ancestor.
foundExistingAncestor = true
break
}
if !oserror.IsNotExist(err) {
return nil, err
}
}
// Handle empty filesystem edge case.
if !foundExistingAncestor {
parentPaths = append(parentPaths, "")
}
// Create destDir and any of its missing parents.
if err := fs.MkdirAll(destDir, 0755); err != nil {
return nil, err

View File

@@ -2,8 +2,8 @@
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//go:build 386 || amd64p32 || arm || armbe || mips || mipsle || mips64p32 || mips64p32le || ppc || sparc
// +build 386 amd64p32 arm armbe mips mipsle mips64p32 mips64p32le ppc sparc
//go:build 386 || amd64p32 || arm || armbe || ppc || sparc
// +build 386 amd64p32 arm armbe ppc sparc
package manual

View File

@@ -2,8 +2,8 @@
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//go:build amd64 || arm64 || arm64be || ppc64 || ppc64le || mips64 || mips64le || s390x || sparc64 || riscv64
// +build amd64 arm64 arm64be ppc64 ppc64le mips64 mips64le s390x sparc64 riscv64
//go:build amd64 || arm64 || arm64be || ppc64 || ppc64le || mips64 || mips64le || s390x || sparc64 || riscv64 || loong64
// +build amd64 arm64 arm64be ppc64 ppc64le mips64 mips64le s390x sparc64 riscv64 loong64
package manual

View File

@@ -0,0 +1,13 @@
// Copyright 2020 The LevelDB-Go and Pebble Authors. All rights reserved. Use
// of this source code is governed by a BSD-style license that can be found in
// the LICENSE file.
//go:build mips || mipsle || mips64p32 || mips64p32le
// +build mips mipsle mips64p32 mips64p32le
package manual
const (
// MaxArrayLen is a safe maximum length for slices on this architecture.
MaxArrayLen = 1 << 30
)

View File

@@ -12,8 +12,8 @@
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//go:build 386 || amd64p32 || arm || armbe || mips || mipsle || mips64p32 || mips64p32le || ppc || sparc
// +build 386 amd64p32 arm armbe mips mipsle mips64p32 mips64p32le ppc sparc
//go:build 386 || amd64p32 || arm || armbe || ppc || sparc
// +build 386 amd64p32 arm armbe ppc sparc
package rawalloc

View File

@@ -12,8 +12,8 @@
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//go:build amd64 || arm64 || arm64be || ppc64 || ppc64le || mips64 || mips64le || s390x || sparc64 || riscv64
// +build amd64 arm64 arm64be ppc64 ppc64le mips64 mips64le s390x sparc64 riscv64
//go:build amd64 || arm64 || arm64be || ppc64 || ppc64le || mips64 || mips64le || s390x || sparc64 || riscv64 || loong64
// +build amd64 arm64 arm64be ppc64 ppc64le mips64 mips64le s390x sparc64 riscv64 loong64
package rawalloc

View File

@@ -0,0 +1,22 @@
// Copyright 2014 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//go:build mips || mipsle || mips64p32 || mips64p32le
// +build mips mipsle mips64p32 mips64p32le
package rawalloc
const (
maxArrayLen = 1 << 30
)

View File

@@ -164,6 +164,9 @@ func (y *MemFS) walk(fullname string, f func(dir *memNode, frag string, final bo
for len(fullname) > 0 && fullname[0] == sep[0] {
fullname = fullname[1:]
}
if fullname == "." {
fullname = ""
}
dir := y.root
for {

View File

@@ -130,6 +130,16 @@ func (b *StringBuilder) SafeRune(s i.SafeRune) {
_ = b.Buffer.WriteRune(rune(s))
}
func (b *StringBuilder) SafeByte(s i.SafeByte) {
b.SetMode(ib.SafeEscaped)
_ = b.Buffer.WriteByte(byte(s))
}
func (b *StringBuilder) SafeBytes(s i.SafeBytes) {
b.SetMode(ib.SafeEscaped)
_, _ = b.Buffer.Write([]byte(s))
}
// UnsafeString is part of the SafeWriter interface.
func (b *StringBuilder) UnsafeString(s string) {
b.SetMode(ib.UnsafeEscaped)

View File

@@ -65,6 +65,12 @@ type SafeWriter interface {
// SafeRune emits a safe rune.
SafeRune(SafeRune)
// SafeByte emits a safe byte.
SafeByte(SafeByte)
// SafeBytes emits a safe byte slice.
SafeBytes(SafeBytes)
// Print emits its arguments separated by spaces.
// For each argument it dynamically checks for the SafeFormatter or
// SafeValue interface and either use that, or mark the argument
@@ -119,6 +125,18 @@ type SafeRune rune
// SafeValue makes SafeRune a SafeValue.
func (SafeRune) SafeValue() {}
// SafeByte represents a byte that is not a sensitive value.
type SafeByte byte
// SafeValue makes SafeByte a SafeValue.
func (SafeByte) SafeValue() {}
// SafeBytes represents a byte slice that is not a sensitive value.
type SafeBytes []byte
// SafeValue makes SafeBytes a SafeValue.
func (SafeBytes) SafeValue() {}
// SafeValue is a marker interface to be implemented by types that
// alias base Go types and whose natural representation via Printf is
// always safe for reporting.

View File

@@ -46,6 +46,18 @@ func (p *pp) SafeRune(r i.SafeRune) {
p.buf.WriteRune(rune(r))
}
// SafeByte implements SafePrinter.
func (p *pp) SafeByte(r i.SafeByte) {
defer p.startSafeOverride().restore()
p.buf.WriteByte(byte(r))
}
// SafeBytes implements SafePrinter.
func (p *pp) SafeBytes(r i.SafeBytes) {
defer p.startSafeOverride().restore()
p.buf.Write(r)
}
func (p *pp) Print(args ...interface{}) {
defer p.buf.SetMode(p.buf.GetMode())
np := newPrinter()