utils

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBase64String

func DecodeBase64String(in string) (out []byte, err error)

DecodeBase64String is a flexible base64 decoder that supports both standard and url encodings, and considers padding optional

func FileExists

func FileExists(path string) (bool, error)

FileExists returns true if a file exists on disk and is a regular file

func IsTruthy

func IsTruthy(str string) bool

IsTruthy returns true if a string is truthy, such as "1", "on", "yes", "true", "t", "y"

func RandomString

func RandomString() (string, error)

RandomString generates a random string of 20 base64url-encoded characters

func WatchFolder

func WatchFolder(ctx context.Context, folder string, logger *zerolog.Logger) (<-chan struct{}, error)

WatchFolder returns a channel that receives a notification when a file is changed in a folder.

Types

type AppLogger

type AppLogger struct {
	// Optional "app" field to add
	App string
	// contains filtered or unexported fields
}

AppLogger is used to write custom logs

func (*AppLogger) Init

func (a *AppLogger) Init() error

Init the object with the default writer for gin

func (*AppLogger) InitWithWriter

func (a *AppLogger) InitWithWriter(out io.Writer) error

InitWithWriter inits the object with a specified output writer

func (*AppLogger) Log

func (a *AppLogger) Log(c *gin.Context) *zerolog.Logger

Log returns a zerolog.Logger with data to append for custom logging

func (*AppLogger) LoggerMaskMiddleware

func (a *AppLogger) LoggerMaskMiddleware(exp *regexp.Regexp, replace string) gin.HandlerFunc

LoggerMaskMiddleware returns a Gin middleware that adds the "log-mask" to mask the path using a regular expression

func (*AppLogger) LoggerMiddleware

func (a *AppLogger) LoggerMiddleware(c *gin.Context)

LoggerMiddleware is a Gin middleware that uses zerlog for logging

func (*AppLogger) Raw

func (a *AppLogger) Raw() *zerolog.Logger

Raw returns the raw zerolog.Logger instances

func (*AppLogger) SetLogLevel

func (a *AppLogger) SetLogLevel(level zerolog.Level)

SetLogLevel updates the logger to set

type Broker

type Broker[T any] struct {
	// contains filtered or unexported fields
}

Broker is a message broker that publishes events to all subscribers

func NewBroker

func NewBroker[T any]() *Broker[T]

NewBroker returns a new Broker object

func (*Broker[T]) Publish

func (b *Broker[T]) Publish(msg T)

Publish sends a message to all subscribers

func (*Broker[T]) Shutdown

func (b *Broker[T]) Shutdown()

Shutdown forcefully closes all subscriptions Then, it marks the broker as shut down

func (*Broker[T]) Subscribe

func (b *Broker[T]) Subscribe() (chan T, error)

Subscribe creates a new subscription

func (*Broker[T]) Unsubscribe

func (b *Broker[T]) Unsubscribe(ch chan T)

Unsubscribe removes a subscription The channel is closed by this method

type Webhook

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

Webhook client

func (*Webhook) Init

func (w *Webhook) Init(log *AppLogger)

Init the object

func (*Webhook) SendWebhook

func (w *Webhook) SendWebhook(ctx context.Context, data *WebhookRequest) (err error)

SendWebhook sends the notification

type WebhookRequest

type WebhookRequest struct {
	OperationName string
	KeyId         string
	Vault         string
	StateId       string
	Requestor     string
	Note          string
}

Jump to

Keyboard shortcuts

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