misc

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 5 Imported by: 4

Documentation

Overview

Package misc provides miscellaneous functions and types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttributesSpanDecorator

func AttributesSpanDecorator(span trace.Span, params, results map[string]interface{})

AttributesSpanDecorator is used alongside with gowrap's generated proxy, to format the span with arguments and results as independent span attributes.

Example of go:generate:

//go:generate gowrap gen -g -p . -i tracingClient -t opentelemetry -o client_trace_gen.go

Example of injecting:

 someservicepkgClient := someservicepkg.NewtracingClientWithTracing(
   someservicepkg.NewClient(factory.ObjectRepository()), // original client
   "someservicepkg", // name of the service that will appear in span
   gowrap.AttributesSpanDecorator,
)

func ListAll

func ListAll[T any](startPage int, listFn func(page int) ([]T, error)) ([]T, error)

ListAll lists objects by batches.

func Map

func Map[T, R any](s []T, f func(T) R) []R

Map applies f to each element of s and returns the result.

func PtrTernary

func PtrTernary[T any](cond *bool, ifTrue, ifFalse T) T

PtrTernary returns ifTrue if cond is true, ifFalse if cond is false, and empty value otherwise.

Types

type ErrAtPage

type ErrAtPage struct {
	Page int
	Err  error
}

ErrAtPage is an error with a page number.

func (ErrAtPage) Error

func (e ErrAtPage) Error() string

Error implements error interface.

func (ErrAtPage) Unwrap

func (e ErrAtPage) Unwrap() error

Unwrap implements error interface.

type Filter

type Filter[T any] struct {
	Include []T
	Exclude []T
}

Filter is a filter for a list of items.

type Pagination

type Pagination struct {
	PerPage int
	Page    int
}

Pagination specifies pagination parameters.

func (Pagination) Empty

func (p Pagination) Empty() bool

Empty returns true if pagination is empty.

type Sort

type Sort struct {
	By    SortBy
	Order SortOrder
}

Sort specifies parameters for ordering.

type SortBy

type SortBy string

SortBy specifies a field to sort by.

const (
	// SortByCreatedAt sorts by created at.
	SortByCreatedAt SortBy = "created_at"
	// SortByTitle sorts by title.
	SortByTitle SortBy = "title"
	// SortByUpdatedAt sorts by updated at.
	SortByUpdatedAt SortBy = "updated_at"
)

type SortOrder

type SortOrder string

SortOrder specifies a sort order.

const (
	// SortOrderAsc sorts in ascending order.
	SortOrderAsc SortOrder = "asc"
	// SortOrderDesc sorts in descending order.
	SortOrderDesc SortOrder = "desc"
)

Jump to

Keyboard shortcuts

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