common

package
v0.0.0-...-27e9e22 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Inspired by github.com/wercker/journalhook (MIT license)

Index

Constants

View Source
const (
	KiloByte = 1000                      // kB
	KibiByte = 1024                      // KiB
	MegaByte = 1000 * 1000               // MB
	MebiByte = 1024 * 1024               // MiB
	GigaByte = 1000 * 1000 * 1000        // GB
	GibiByte = 1024 * 1024 * 1024        // GiB
	TeraByte = 1000 * 1000 * 1000 * 1000 // TB
	TebiByte = 1024 * 1024 * 1024 * 1024 // TiB
)
View Source
const ExternalIDKey string = "externalID"
View Source
const (
	OSBuildImagesModulePath = "github.com/osbuild/images"
)
View Source
const OperationIDKey string = "operationID"

Variables

View Source
var (
	// Git revision from which this code was built
	GitRev = "undefined"

	// RPM Version
	RpmVersion = "undefined"
)

These constants are set during buildtime using additional compiler flags. Not all of them are necessarily defined because RPMs can be build from a tarball and spec file without being in a git repository. On the other hand when building composer inside of a container, there is no RPM layer so in that case the RPM version doesn't exist at all.

Functions

func BuildVersion

func BuildVersion() string

func DataSizeToUint64

func DataSizeToUint64(size string) (uint64, error)

DataSizeToUint64 converts a size specified as a string in KB/KiB/MB/etc. to a number of bytes represented by uint64.

func ExternalIDMiddleware

func ExternalIDMiddleware(next echo.HandlerFunc) echo.HandlerFunc

Extracts HTTP header X-External-Id and sets it as a request context value

func GenerateOperationID

func GenerateOperationID() string

func GetDepModuleInfoByPath

func GetDepModuleInfoByPath(path string) (*debug.Module, error)

GetDepModuleInfoByPath returns the debug.Module for the dependency with the given path. If the dependency is not found, an error is returned.

func IsStringInSortedSlice

func IsStringInSortedSlice(slice []string, s string) bool

IsStringInSortedSlice returns true if the string is present, false if not slice must be sorted

func LoggerMiddleware

func LoggerMiddleware(next echo.HandlerFunc) echo.HandlerFunc

Store context in request logger to propagate correlation ids

func NopSeekCloser

func NopSeekCloser(r io.ReadSeeker) io.ReadSeekCloser

NopSeekCloser returns an io.ReadSeekCloser with a no-op Close method wrapping the provided io.ReadSeeker r.

func OperationIDMiddleware

func OperationIDMiddleware(next echo.HandlerFunc) echo.HandlerFunc

Adds a time-sortable globally unique identifier to an echo.Context if not already set

func PanicOnError

func PanicOnError(err error)

func ToPtr

func ToPtr[T any](x T) *T

Types

type ContextHook

type ContextHook struct{}

func (*ContextHook) Fire

func (h *ContextHook) Fire(e *logrus.Entry) error

func (*ContextHook) Levels

func (h *ContextHook) Levels() []logrus.Level

type CustomJsonConversionError

type CustomJsonConversionError struct {
	// contains filtered or unexported fields
}

CustomJsonConversionError is thrown when parsing strings into enumerations

func (*CustomJsonConversionError) Error

func (err *CustomJsonConversionError) Error() string

Error returns the error as a string

type CustomTypeError

type CustomTypeError struct {
	// contains filtered or unexported fields
}

CustomTypeError is thrown when parsing strings into enumerations

func (*CustomTypeError) Error

func (err *CustomTypeError) Error() string

Error returns the error as a string

type EchoLogrusLogger

type EchoLogrusLogger struct {
	*logrus.Logger
	Ctx context.Context
}

EchoLogrusLogger extend logrus.Logger

func Logger

func Logger() *EchoLogrusLogger

func (*EchoLogrusLogger) Debug

func (l *EchoLogrusLogger) Debug(i ...interface{})

func (*EchoLogrusLogger) Debugf

func (l *EchoLogrusLogger) Debugf(format string, args ...interface{})

func (*EchoLogrusLogger) Debugj

func (l *EchoLogrusLogger) Debugj(j lslog.JSON)

func (*EchoLogrusLogger) Error

func (l *EchoLogrusLogger) Error(i ...interface{})

func (*EchoLogrusLogger) Errorf

func (l *EchoLogrusLogger) Errorf(format string, args ...interface{})

func (*EchoLogrusLogger) Errorj

func (l *EchoLogrusLogger) Errorj(j lslog.JSON)

func (*EchoLogrusLogger) Fatal

func (l *EchoLogrusLogger) Fatal(i ...interface{})

func (*EchoLogrusLogger) Fatalf

func (l *EchoLogrusLogger) Fatalf(format string, args ...interface{})

func (*EchoLogrusLogger) Fatalj

func (l *EchoLogrusLogger) Fatalj(j lslog.JSON)

func (*EchoLogrusLogger) Info

func (l *EchoLogrusLogger) Info(i ...interface{})

func (*EchoLogrusLogger) Infof

func (l *EchoLogrusLogger) Infof(format string, args ...interface{})

func (*EchoLogrusLogger) Infoj

func (l *EchoLogrusLogger) Infoj(j lslog.JSON)

func (*EchoLogrusLogger) Level

func (l *EchoLogrusLogger) Level() lslog.Lvl

func (*EchoLogrusLogger) Output

func (l *EchoLogrusLogger) Output() io.Writer

func (*EchoLogrusLogger) Panic

func (l *EchoLogrusLogger) Panic(i ...interface{})

func (*EchoLogrusLogger) Panicf

func (l *EchoLogrusLogger) Panicf(format string, args ...interface{})

func (*EchoLogrusLogger) Panicj

func (l *EchoLogrusLogger) Panicj(j lslog.JSON)

func (*EchoLogrusLogger) Prefix

func (l *EchoLogrusLogger) Prefix() string

func (*EchoLogrusLogger) Print

func (l *EchoLogrusLogger) Print(i ...interface{})

func (*EchoLogrusLogger) Printf

func (l *EchoLogrusLogger) Printf(format string, args ...interface{})

func (*EchoLogrusLogger) Printj

func (l *EchoLogrusLogger) Printj(j lslog.JSON)

func (*EchoLogrusLogger) SetHeader

func (l *EchoLogrusLogger) SetHeader(h string)

func (*EchoLogrusLogger) SetLevel

func (l *EchoLogrusLogger) SetLevel(v lslog.Lvl)

func (*EchoLogrusLogger) SetOutput

func (l *EchoLogrusLogger) SetOutput(w io.Writer)

func (*EchoLogrusLogger) SetPrefix

func (l *EchoLogrusLogger) SetPrefix(p string)

func (*EchoLogrusLogger) Warn

func (l *EchoLogrusLogger) Warn(i ...interface{})

func (*EchoLogrusLogger) Warnf

func (l *EchoLogrusLogger) Warnf(format string, args ...interface{})

func (*EchoLogrusLogger) Warnj

func (l *EchoLogrusLogger) Warnj(j lslog.JSON)

func (*EchoLogrusLogger) Write

func (l *EchoLogrusLogger) Write(p []byte) (n int, err error)

type ImageBuildState

type ImageBuildState int
const (
	IBWaiting ImageBuildState = iota
	IBRunning
	IBFinished
	IBFailed
)

func (ImageBuildState) MarshalJSON

func (ibs ImageBuildState) MarshalJSON() ([]byte, error)

func (ImageBuildState) ToString

func (ibs ImageBuildState) ToString() string

ToString converts ImageBuildState into a human readable string

func (*ImageBuildState) UnmarshalJSON

func (ibs *ImageBuildState) UnmarshalJSON(data []byte) error

UnmarshalJSON converts a JSON string into an ImageBuildState

type JournalHook

type JournalHook struct{}

func (*JournalHook) Fire

func (hook *JournalHook) Fire(entry *logrus.Entry) error

func (*JournalHook) Levels

func (hook *JournalHook) Levels() []logrus.Level

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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