Documentation ¶
Index ¶
- func AcquireSemaphore(ctx context.Context, semaphore *semaphore.Weighted, count int) error
- func DecimalExponentialBuckets(lowestPowerOf10, powersOf10, stepsInBetween int) []float64
- func IsInfrastructureError(err error) bool
- func NewTLSConfigFromClientConfiguration(configuration *pb.ClientConfiguration) (*tls.Config, error)
- func NewTLSConfigFromServerConfiguration(configuration *pb.ServerConfiguration, requestClientCertificate bool) (*tls.Config, error)
- func StatusFromContext(ctx context.Context) error
- func StatusFromMultiple(errs []error) error
- func StatusWrap(err error, msg string) error
- func StatusWrapWithCode(err error, code codes.Code, msg string) error
- func StatusWrapf(err error, format string, args ...interface{}) error
- func StatusWrapfWithCode(err error, code codes.Code, format string, args ...interface{}) error
- func UnmarshalConfigurationFromFile(path string, configuration proto.Message) error
- func VisitProtoBytesFields(r io.Reader, visitor ProtoBytesFieldVisitor) error
- type ErrorLogger
- type NonEmptyStack
- type ProtoBytesFieldVisitor
- type RotatingTLSCertificate
- type UUIDGenerator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcquireSemaphore ¶
AcquireSemaphore acquires a weighted semaphore.
Weighted.Acquire() does not check for context cancellation prior to acquiring. This means that if the semaphore is acquired in a tight loop, the loop will not be interrupted. This helper function rectifies that.
func DecimalExponentialBuckets ¶
DecimalExponentialBuckets generates a series of exponential bucket boundaries that can be used for Prometheus histogram objects. Instead of using powers of 2, this function uses 10^(1/m) as the exponent. This has the advantage of yielding round numbers at every power of ten.
Instead of computing the actual value of 10^(n/m), we first compute values that are up to five digits accurate within a single power of 10. This is done to ensure that the metric label name remains short and unaffected by the precision of math libraries and hardware floating point units.
Under the hood, strconv.ParseFloat() is used. Unlike math.Pow(), it ensures that the resulting floating point value is the one that yields the desired shortest decimal representation.
func IsInfrastructureError ¶
IsInfrastructureError returns true if an error is caused by a failure of the infrastructure, as opposed to it being caused by a parameter provided by the caller.
This function may, for example, be used to determine whether a call should be retried.
func NewTLSConfigFromClientConfiguration ¶
func NewTLSConfigFromClientConfiguration(configuration *pb.ClientConfiguration) (*tls.Config, error)
NewTLSConfigFromClientConfiguration creates a TLS configuration object based on parameters specified in a Protobuf message for use with a TLS client. This Protobuf message is embedded in Buildbarn configuration files.
func NewTLSConfigFromServerConfiguration ¶
func NewTLSConfigFromServerConfiguration(configuration *pb.ServerConfiguration, requestClientCertificate bool) (*tls.Config, error)
NewTLSConfigFromServerConfiguration creates a TLS configuration object based on parameters specified in a Protobuf message for use with a TLS server. This Protobuf message is embedded in Buildbarn configuration files.
func StatusFromContext ¶
StatusFromContext converts the error associated with a context to a gRPC Status error. This function ensures that errors such as context.DeadlineExceeded are properly converted to Status objects having the code DEADLINE_EXCEEDED.
func StatusFromMultiple ¶
StatusFromMultiple creates a single error object based on multiple errors. The status code and metadata from the first error is used, while the messages are all concatenated and comma separated.
func StatusWrap ¶
StatusWrap prepends a string to the message of an existing error.
func StatusWrapWithCode ¶
StatusWrapWithCode prepends a string to the message of an existing error, while replacing the error code.
func StatusWrapf ¶
StatusWrapf prepends a formatted string to the message of an existing error.
func StatusWrapfWithCode ¶
StatusWrapfWithCode prepends a formatted string to the message of an existing error, while replacing the error code.
func UnmarshalConfigurationFromFile ¶
UnmarshalConfigurationFromFile reads a Jsonnet file, evaluates it and unmarshals the output into a Protobuf message.
func VisitProtoBytesFields ¶
func VisitProtoBytesFields(r io.Reader, visitor ProtoBytesFieldVisitor) error
VisitProtoBytesFields reads a marshaled Protobuf message from a Reader and calls into ProtoBytesFieldVisitor for any top-level field that it encounters.
As the name suggests, this function is only capable of parsing message fields that use wire type 2, which is used for bytes, strings, embedded messages, and packed repeated fields.
Types ¶
type ErrorLogger ¶
type ErrorLogger interface {
Log(err error)
}
ErrorLogger may be used to report errors. Implementations may decide to log, mutate, redirect and discard them. This interface is used in places where errors are generated asynchronously, meaning they cannot be returned to the caller directly.
var DefaultErrorLogger ErrorLogger = defaultErrorLogger{}
DefaultErrorLogger writes errors using Go's standard logging package.
type NonEmptyStack ¶
type NonEmptyStack[T any] struct { // contains filtered or unexported fields }
NonEmptyStack is a stack data type that, if initialized properly, is guaranteed to remain non-empty.
func NewNonEmptyStack ¶
func NewNonEmptyStack[T any](base T) NonEmptyStack[T]
NewNonEmptyStack returns a non-empty stack that is initialized with a single element.
func (*NonEmptyStack[T]) Copy ¶
func (cw *NonEmptyStack[T]) Copy() NonEmptyStack[T]
Copy all of the elements in a non-empty stack, returning a new instance.
func (*NonEmptyStack[T]) Peek ¶
func (cw *NonEmptyStack[T]) Peek() T
Peek at the element that was last pushed into the stack.
func (*NonEmptyStack[T]) PopAll ¶
func (cw *NonEmptyStack[T]) PopAll()
PopAll removes all but the first element from the non-empty stack.
func (*NonEmptyStack[T]) PopSingle ¶
func (cw *NonEmptyStack[T]) PopSingle() (T, bool)
PopSingle removes the last pushed element from the stack. The return value indicates whether an element was popped successfully. It is not possible to pop the final element off the stack.
func (*NonEmptyStack[T]) Push ¶
func (cw *NonEmptyStack[T]) Push(d T)
Push a new element on top of the stack.
type ProtoBytesFieldVisitor ¶
type ProtoBytesFieldVisitor func(fieldNumber protowire.Number, offsetBytes, sizeBytes int64, fieldReader io.Reader) error
ProtoBytesFieldVisitor is the callback type that is used by VisitProtoBytesFields to report individual fields.
type RotatingTLSCertificate ¶
type RotatingTLSCertificate struct {
// contains filtered or unexported fields
}
RotatingTLSCertificate provides an up-to-date certificate given file paths and a refresh interval.
func NewRotatingTLSCertificate ¶
func NewRotatingTLSCertificate(certFile, keyFile string) *RotatingTLSCertificate
NewRotatingTLSCertificate creates TLS certificate provider object based on parameters specified in a Protobuf message for use with a TLS client. This Protobuf message is embedded in Buildbarn configuration files.
func (*RotatingTLSCertificate) GetCertificate ¶
func (r *RotatingTLSCertificate) GetCertificate() *tls.Certificate
GetCertificate provides the most recently obtained semantically valid tls.Certificate.
func (*RotatingTLSCertificate) LoadCertificate ¶
func (r *RotatingTLSCertificate) LoadCertificate() error
LoadCertificate from files on disk. Aborts if the files have not changed.
type UUIDGenerator ¶
UUIDGenerator is equal to the signature of the UUID library's UUID generation functions. It is used within this codebase to make the generator injectable as part of unit tests.