Help us shape the future of Go! Take the 2026 Go Developer Survey

utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunks

func Chunks[T any](slice []T, chunkSize int) [][]T

Chunks splits a slice into chunks of the specified size

func ExtractDOI

func ExtractDOI(doi string) string

ExtractDOI extracts the DOI from a given DOI string, removing any prefixes.

func GetDBPath added in v0.3.0

func GetDBPath(ctx context.Context) (string, bool)

GetDBPath retrieves the SQLite database file path from the context if present.

func GetRootDir

func GetRootDir(ctx context.Context) (string, bool)

GetRootDir retrieves the root directory from the context if present.

func InvertAbstract

func InvertAbstract(abstractInvertedIndex *map[string][]int) string

InvertAbstract returns the string representation of an inverted abstract.

func InvertName

func InvertName(name string) string

InvertName inverts the name from "First Last" to "Last, First".

func Keep

func Keep[T any](options ...*T) *T

Keep returns the first non-nil option from the given list of options.

func KeepLongestSlice

func KeepLongestSlice[T any](a, b []T) []T

KeepLongestSlice returns the longest of two slices

func KeepLongestString

func KeepLongestString(a, b string) string

KeepLongestString returns the longest of two strings.

func Limit

func Limit[T any](slice []T, n int, compare func(a, b T) int) []T

Limit sorts the slice using compare and returns at most n elements.

func SetDefaultLogger

func SetDefaultLogger(verbose bool)

SetDefaultLogger configures and registers the default application slog logger using tinted console output.

func WithDBPath added in v0.3.0

func WithDBPath(ctx context.Context, dbPath string) context.Context

WithDBPath overrides the database path in the context.

func WithRootDir

func WithRootDir(ctx context.Context, rootDir string) context.Context

WithRootDir attaches the root directory and default SQLite DB path to the context.

func WrapText

func WrapText(text string, limit int) string

WrapText wraps the given text to a maximum line length of limit.

Types

type ContextKey

type ContextKey string

ContextKey represents context keys used for storing and retrieving configuration values.

type FoldedString

type FoldedString string

FoldedString is a string type that serializes to YAML using folded style (>).

func NewFoldedString

func NewFoldedString(s *string) *FoldedString

NewFoldedString creates a new FoldedString pointer from a string pointer.

func (FoldedString) MarshalYAML

func (f FoldedString) MarshalYAML() (any, error)

MarshalYAML implements the yaml.Marshaler interface using folded style.

Jump to

Keyboard shortcuts

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