lib

package module
v0.0.0-...-5f93962 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: Apache-2.0 Imports: 6 Imported by: 5

README

go-lib

Library for Golang containing the code I end up using in all my Go projects

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LeadingSpaces

func LeadingSpaces(s string) (n int)

LeadingSpaces returns the number of leading spaces in a string, e.g.

LeadingSpaces("foo")    => 0
LeadingSpaces(" foo")   => 1
LeadingSpaces("  foo")  => 2
LeadingSpaces("   foo") => 3

func OneOf

func OneOf[T comparable](val T, options ...T) bool

func Panicf

func Panicf(msg string, args ...any)

func RightShift

func RightShift[S []E, E any](s S, e ...E) S

func TrailingSpaces

func TrailingSpaces(s string) (n int)

TrailingSpaces returns the number of trailing spaces in a string, e.g.

TrailingSpaces("bar")    => 0
TrailingSpaces("bar ")   => 1
TrailingSpaces("bar  ")  => 2
TrailingSpaces("bar   ") => 3

func UpperFirst

func UpperFirst(s string) (_ string)

Types

type SLogBufferHandler

type SLogBufferHandler struct {
	FormatFunc func(record slog.Record) string
	// contains filtered or unexported fields
}

SLogBufferHandler is a custom log handler that writes logs to a bytes.Buffer.

func NewSLogBufferHandler

func NewSLogBufferHandler() *SLogBufferHandler

NewSLogBufferHandler creates a new SLogBufferHandler.

func (*SLogBufferHandler) Content

func (h *SLogBufferHandler) Content() string

Content returns the content of the log buffer.

func (*SLogBufferHandler) Enabled

func (h *SLogBufferHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled checks if the log level is enabled.

func (*SLogBufferHandler) Handle

func (h *SLogBufferHandler) Handle(ctx context.Context, record slog.Record) error

Handle processes the log record.

func (*SLogBufferHandler) WithAttrs

func (h *SLogBufferHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new handler with added attributes.

func (*SLogBufferHandler) WithGroup

func (h *SLogBufferHandler) WithGroup(name string) slog.Handler

WithGroup returns a new handler with the given group name. If the group name is empty, it returns the same handler.

type Stack

type Stack[T comparable] struct {
	// contains filtered or unexported fields
}

func (*Stack[T]) Depth

func (s *Stack[T]) Depth() int

func (*Stack[T]) Drop

func (s *Stack[T]) Drop()

func (*Stack[T]) Empty

func (s *Stack[T]) Empty() bool

func (*Stack[T]) Has

func (s *Stack[T]) Has(v T) (has bool)

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

func (*Stack[T]) Push

func (s *Stack[T]) Push(v T)

func (*Stack[T]) Top

func (s *Stack[T]) Top() T

Jump to

Keyboard shortcuts

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