helper

package
v14.10.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxCommitOrTagMessageSize = 10 * 1024

MaxCommitOrTagMessageSize is the threshold for a commit/tag message, if exceeded then message is truncated and it's up to the client to request it in full separately.

Functions

func ByteSliceHasAnyPrefix

func ByteSliceHasAnyPrefix(s []byte, prefixes ...string) bool

ByteSliceHasAnyPrefix tests whether the byte slice s begins with any of the prefixes.

func CheckClockSync added in v14.8.0

func CheckClockSync(ntpHost string, driftThreshold time.Duration) (bool, error)

CheckClockSync checks if machine clock has allowed drift threshold compare to NTP service. ntpHost is a URL of the NTP service to query, if not set the default pool.ntp.org is used. driftThreshold is a time duration that is considered acceptable time offset.

func ErrAborted added in v14.10.0

func ErrAborted(err error) error

ErrAborted wraps err with codes.Aborted, unless err is already a gRPC error.

func ErrAbortedf added in v14.10.0

func ErrAbortedf(format string, a ...interface{}) error

ErrAbortedf wraps a formatted error with codes.Aborted, unless the formatted error is a wrapped gRPC error.

func ErrAlreadyExists added in v14.3.0

func ErrAlreadyExists(err error) error

ErrAlreadyExists wraps err with codes.AlreadyExists, unless err is already a gRPC error.

func ErrAlreadyExistsf added in v14.6.0

func ErrAlreadyExistsf(format string, a ...interface{}) error

ErrAlreadyExistsf wraps a formatted error with codes.AlreadyExists, unless the formatted error is a wrapped gRPC error.

func ErrCanceled added in v14.2.0

func ErrCanceled(err error) error

ErrCanceled wraps err with codes.Canceled, unless err is already a gRPC error.

func ErrFailedPrecondition added in v14.2.0

func ErrFailedPrecondition(err error) error

ErrFailedPrecondition wraps err with codes.FailedPrecondition, unless err is already a gRPC error.

func ErrFailedPreconditionf added in v14.2.0

func ErrFailedPreconditionf(format string, a ...interface{}) error

ErrFailedPreconditionf wraps a formatted error with codes.FailedPrecondition, unless the formatted error is a wrapped gRPC error.

func ErrInternal

func ErrInternal(err error) error

ErrInternal wraps err with codes.Internal, unless err is already a gRPC error.

func ErrInternalf

func ErrInternalf(format string, a ...interface{}) error

ErrInternalf wraps a formatted error with codes.Internal, unless the formatted error is a wrapped gRPC error.

func ErrInvalidArgument

func ErrInvalidArgument(err error) error

ErrInvalidArgument wraps err with codes.InvalidArgument, unless err is already a gRPC error.

func ErrInvalidArgumentf

func ErrInvalidArgumentf(format string, a ...interface{}) error

ErrInvalidArgumentf wraps a formatted error with codes.InvalidArgument, unless the formatted error is a wrapped gRPC error.

func ErrNotFound

func ErrNotFound(err error) error

ErrNotFound wraps error with codes.NotFound, unless err is already a gRPC error.

func ErrNotFoundf added in v14.2.0

func ErrNotFoundf(format string, a ...interface{}) error

ErrNotFoundf wraps a formatted error with codes.NotFound, unless the formatted error is a wrapped gRPC error.

func ErrPermissionDenied added in v14.3.0

func ErrPermissionDenied(err error) error

ErrPermissionDenied wraps err with codes.PermissionDenied, unless err is already a gRPC error.

func ErrPermissionDeniedf added in v14.3.0

func ErrPermissionDeniedf(format string, a ...interface{}) error

ErrPermissionDeniedf wraps a formatted error with codes.PermissionDenied, unless the formatted error is a wrapped gRPC error.

func ErrUnavailable added in v14.2.0

func ErrUnavailable(err error) error

ErrUnavailable wraps err with codes.Unavailable, unless err is already a gRPC error.

func ErrUnavailablef added in v14.2.0

func ErrUnavailablef(format string, a ...interface{}) error

ErrUnavailablef wraps a formatted error with codes.Unavailable, unless the formatted error is a wrapped gRPC error.

func ErrWithDetails added in v14.3.0

func ErrWithDetails(err error, details ...proto.Message) (error, error)

ErrWithDetails adds the given details to the error if it is a gRPC status whose code is not OK.

func GrpcCode

func GrpcCode(err error) codes.Code

GrpcCode emulates the old grpc.Code function: it translates errors into codes.Code values.

func IsNumber

func IsNumber(s []byte) bool

IsNumber tests whether the byte slice s contains only digits or not

func RepoPathEqual

func RepoPathEqual(a, b repository.GitRepo) bool

RepoPathEqual compares if two repositories are in the same location

func SanitizeError

func SanitizeError(err error) error

SanitizeError does the same thing as SanitizeString but for error types

func SanitizeString

func SanitizeString(str string) string

SanitizeString will clean password and tokens from URLs, and replace them with [FILTERED].

func SuppressCancellation

func SuppressCancellation(ctx context.Context) context.Context

SuppressCancellation returns a context that suppresses cancellation or expiration of the parent context.

func UnquoteBytes

func UnquoteBytes(s []byte) []byte

UnquoteBytes removes surrounding double-quotes from a byte slice returning a new slice if they exist, otherwise it returns the same byte slice passed.

Types

type CountingWriter added in v14.6.0

type CountingWriter struct {
	W io.Writer
	N int64
}

CountingWriter wraps an io.Writer and counts all the writes. Accessing the count N is not thread-safe.

func (*CountingWriter) Write added in v14.6.0

func (cw *CountingWriter) Write(p []byte) (int, error)

type ManualTicker

type ManualTicker struct {
	StopFunc  func()
	ResetFunc func()
	// contains filtered or unexported fields
}

ManualTicker implements a ticker that ticks when Tick is called. Stop and Reset functions call the provided functions.

func NewCountTicker

func NewCountTicker(n int, callback func()) *ManualTicker

NewCountTicker returns a ManualTicker with a ResetFunc that calls the provided callback on Reset call after it has been called N times.

func NewManualTicker

func NewManualTicker() *ManualTicker

NewManualTicker returns a Ticker that can be manually controlled.

func (*ManualTicker) C

func (mt *ManualTicker) C() <-chan time.Time

nolint: revive,stylecheck // This is unintentionally missing documentation.

func (*ManualTicker) Reset

func (mt *ManualTicker) Reset()

nolint: revive,stylecheck // This is unintentionally missing documentation.

func (*ManualTicker) Stop

func (mt *ManualTicker) Stop()

nolint: revive,stylecheck // This is unintentionally missing documentation.

func (*ManualTicker) Tick

func (mt *ManualTicker) Tick()

nolint: revive,stylecheck // This is unintentionally missing documentation.

type Ticker

type Ticker interface {
	C() <-chan time.Time
	Stop()
	Reset()
}

Ticker ticks on the channel returned by C to signal something.

func NewTimerTicker

func NewTimerTicker(interval time.Duration) Ticker

NewTimerTicker returns a Ticker that ticks after the specified interval has passed since the previous Reset call.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL