klib

package module
v0.0.0-...-208a4f9 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

README

This is a collection of utility libraries.

  • graph: Minimal (or almost) set of structs to use directed graphs from gonum.org/v1/gonum/graph.

Documentation

Index

Constants

View Source
const (
	CodeAborted            = "ABORTED"
	CodeAlreadyExists      = "ALREADY_EXISTS"
	CodeBufferError        = "BUFFER_ERROR"
	CodeCanceled           = "CANCELED"
	CodeConditionFailed    = "CONDITION_FAILED"
	CodeDatabaseError      = "DATABASE_ERROR"
	CodeExecutionError     = "EXECUTION_ERROR"
	CodeExpired            = "EXPIRED"
	CodeFileError          = "FILE_ERROR"
	CodeFilesystemError    = "FILESYSTEM_ERROR"
	CodeForwardedError     = "FORWARDED_ERROR"
	CodeInternalError      = "INTERNAL_ERROR"
	CodeInvalidValue       = "INVALID_VALUE"
	CodeMissingValue       = "MISSING_VALUE"
	CodeNetworkError       = "NETWORK_ERROR"
	CodeNotFound           = "NOT_FOUND"
	CodeOpenFileError      = "OPEN_FILE_ERROR"
	CodeParseError         = "PARSE_ERROR"
	CodeSerializationError = "SERIALIZATION_ERROR"
	CodeTypeAssertionError = "TYPE_ASSERTION_ERROR"
	CodeUnauthenticated    = "UNAUTHENTICATED"
	CodeUnauthorized       = "UNAUTHORIZED"
	CodeUnexpectedContent  = "UNEXPECTED_CONTENT"
	CodeUnimplemented      = "UNIMPLEMENTED"
	CodeUnknownError       = "UNKNOWN_ERROR"
	CodeUnsupportedValue   = "UNSUPPORTED_VALUE"
)

Variables

This section is empty.

Functions

func BaseFuncMap

func BaseFuncMap() template.FuncMap

BaseFuncMap returns a template.FuncMap with sprig's GenericFuncMap and additional utility functions.

func BuildInfo

func BuildInfo() string

BuildInfo returns the static string value that holds information set during build, like app version, build version, etc.

func CheckTestError

func CheckTestError(t *testing.T, err error, want *Error) bool

CheckTestError verifies that the given error is the expected error and returns true if err is not null and equals want.

func InsertSliceElem

func InsertSliceElem[T any](slice []T, element T, index int) ([]T, error)

InsertSliceElem inserts element in the given slice and index. If index is negative, it is treated as `index+len(slice)+1`:

  • -1 adds to the end of the slice, i.e., appends the element.
  • -(len(slice)+1) is the same as index=0: it adds to the beginning of the slice, i.e., prepends the element.

Types

type DeployEnv

type DeployEnv int
const (
	// The default, non-ephemeral, deployment environment.
	DeployEnvProduction DeployEnv = 0

	// A remote environment that closely matches production.
	DeployEnvStaging DeployEnv = 10

	// A remote environment to test newly developed features.
	// Can be used to stress-test the infrastructure.
	DeployEnvTesting DeployEnv = 20

	// A remote environment that is used for automated tests,
	// usually when changes are pushed to code repositories.
	DeployEnvCI DeployEnv = 30

	// A local environment that is used for automated tests,
	// usually to ensure tests pass before pushing changes to code repositories.
	DeployEnvLocalCI DeployEnv = 40

	// A local environment that is used for local development or testing.
	DeployEnvLocal DeployEnv = 50
)

type Error

type Error struct {
	// A globally unique identifier.
	ID string `cbor:"1,keyasint,omitempty" json:"id,omitempty"`

	// The HTTP status code applicable to this problem. This SHOULD be provided.
	Status int `cbor:"2,keyasint,omitempty" json:"status,omitempty"`

	// An application-specific error code, expressed as a string value.
	Code string `cbor:"3,keyasint,omitempty" json:"code,omitempty"`

	// A label that can be used as a sub error code, or to better identify the error.
	Label string `cbor:"4,keyasint,omitempty" json:"label,omitempty"`

	// The path to the error, e.g., the input object's field that caused the error.
	Path string `cbor:"5,keyasint,omitempty" json:"path,omitempty"`

	// A short, human-readable summary of the problem that SHOULD NOT change
	// from occurrence to occurrence of the problem, except for purposes of localization.
	Title string `cbor:"6,keyasint,omitempty" json:"title,omitempty"`

	// A human-readable explanation specific to this occurrence of the problem.
	// Like title, this field’s value can be localized.
	Detail string `cbor:"7,keyasint,omitempty" json:"detail,omitempty"`

	// The original error message, from stdlib or external libraries/packages.
	// This is equivalent to jsonapi's "source" field, although we just care
	// about the error message, not additional information.
	Cause string `cbor:"8,keyasint,omitempty" json:"cause,omitempty"`

	// The amount of time to wait before retrying the request.
	RetryDelay time.Duration `cbor:"9,keyasint,omitempty" json:"retryDelay,omitempty"`

	// Available help for the error.
	Help []*HelpLink `cbor:"10,keyasint,omitempty" json:"help,omitempty"`

	// An object containing non-standard meta-information about the error.
	Meta map[string]any `cbor:"11,keyasint,omitempty" json:"meta,omitempty"`
}

Inspired by https://jsonapi.org/format/#error-objects.

func (*Error) Error

func (e *Error) Error() string

To-do: support custom formatter.

type ErrorChain

type ErrorChain []*Error

func ForwardError

func ForwardError(id string, err error) ErrorChain

ForwardError wraps and returns the given error as an ErrorChain. The id is used to identify where the forwarding happened.

func (ErrorChain) Add

func (e ErrorChain) Add(err ...*Error) ErrorChain

func (ErrorChain) Error

func (e ErrorChain) Error() string

func (ErrorChain) First

func (e ErrorChain) First() *Error

func (ErrorChain) Last

func (e ErrorChain) Last() *Error
type HelpLink struct {
	// Describes what the link offers.
	Description string `cbor:"1,keyasint,omitempty" json:"description,omitempty"`

	// The URL of the link.
	URL string `cbor:"2,keyasint,omitempty" json:"url,omitempty"`
}

type MockStringHandler

type MockStringHandler struct {
	mock.Mock
}

MockStringHandler is an autogenerated mock type for the StringHandler type

func NewMockStringHandler

func NewMockStringHandler(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockStringHandler

NewMockStringHandler creates a new instance of MockStringHandler. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockStringHandler) EXPECT

func (*MockStringHandler) Handle

func (_m *MockStringHandler) Handle(input string) (string, error)

Handle provides a mock function with given fields: input

type MockStringHandler_Expecter

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

func (*MockStringHandler_Expecter) Handle

func (_e *MockStringHandler_Expecter) Handle(input interface{}) *MockStringHandler_Handle_Call

Handle is a helper method to define mock.On call

  • input string

type MockStringHandler_Handle_Call

type MockStringHandler_Handle_Call struct {
	*mock.Call
}

MockStringHandler_Handle_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Handle'

func (*MockStringHandler_Handle_Call) Return

func (*MockStringHandler_Handle_Call) Run

func (*MockStringHandler_Handle_Call) RunAndReturn

type StringHandler

type StringHandler interface {
	Handle(input string) (string, error)
}

StringHandler is an interface for processing strings. E.g.: validation, transformation, etc.

Directories

Path Synopsis
package must contains functions that panic on error.
package must contains functions that panic on error.

Jump to

Keyboard shortcuts

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