lang

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 19 Imported by: 6

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNilError

func IsNilError[T Error](err T) bool

IsNilError will return if an Error is nil or not.

func RaiseErr

func RaiseErr(err error) bool

RaiseErr() helps panic a Try() action. To be used around a function returning optionally an error. If the error is not nil it will use it to panic() otherwise it returns false.

func RaiseNilErr

func RaiseNilErr(err error) bool

RaiseNilErr() helps panic a Try() action. To be used around a function returning an object and optionally an error. If the error is not nil it will use it to panic() otherwise it will panic() with an NilError.

It only usage is on untestable situation where an error may occur. It will be returned as an Error, in any cases, letting you can Error.LogError on it and not doing anything if it's a NilError.

func RaiseVal

func RaiseVal[T any](t T, e error) T

RaiseVal() helps panic a Try() action. To be used around a function returning an object and optionally an error. If the error is not nil it will use it to panic() otherwise it returns the object T.

Types

type ByteStringConstraint

type ByteStringConstraint interface {
	~string | ~[]byte
}

ByteStringConstraint is a constraint that permits any byte slice or string. If future releases of Go add new predeclared byte slice or string types, this constraint will be modified to include them.

type ComplexConstraint

type ComplexConstraint interface {
	~complex64 | ~complex128
}

ComplexConstraint is a constraint that permits any complex numeric type. If future releases of Go add new predeclared complex numeric types, this constraint will be modified to include them.

type DefaultError

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

DefaultError is the default implementation of the Error interface.

func NewError

func NewError(name, message string, args ...any) *DefaultError

NewError() creates a new Error with a name, message and optional key-paired arguments.

func (*DefaultError) AddAttribute

func (this *DefaultError) AddAttribute(key string, value any)

AddAttribute() add attributes to the error to ge logged

func (*DefaultError) AddAttributes

func (this *DefaultError) AddAttributes(attr ...any)

AddAttribute() add attributes to the error to ge logged

func (*DefaultError) Error

func (this *DefaultError) Error() string

Error() implements the error interface

func (*DefaultError) Format

func (this *DefaultError) Format(state fmt.State, verb rune)

Formatter interface Format function %s or %v will print the error message Use %+v to also print the Stacktrace

func (*DefaultError) GomegaString

func (this *DefaultError) GomegaString() string

GomegaString() returns the error for Gomega

func (*DefaultError) Log

func (this *DefaultError) Log(level slog.Level, args ...any)

Log() will log the error at the specified level, with optional arguments

func (*DefaultError) LogError

func (this *DefaultError) LogError(args ...any)

LogError() will log the error at Error level, with optional arguments.

func (*DefaultError) LogErrorWithStackTrace

func (this *DefaultError) LogErrorWithStackTrace(args ...any)

LogErrorWithStackTrace() will log the error at Error level, wit hstacktrace and optional arguments

func (*DefaultError) LogWithStackTrace

func (this *DefaultError) LogWithStackTrace(level slog.Level, args ...any)

LogWithStackTrace() will log error with a stacktrace to its creation, with optional arguments.

func (*DefaultError) MarshalJSON

func (this *DefaultError) MarshalJSON() ([]byte, error)

MarshalJSON() will return a JSON version of this error.

func (*DefaultError) Message

func (this *DefaultError) Message() string

Message() returns the error message.

func (*DefaultError) Name

func (this *DefaultError) Name() string

Name() returns the error name.

func (*DefaultError) PrintStacktrace

func (this *DefaultError) PrintStacktrace(out io.Writer)

PrintStacktrace() will write the stacktrace on an io.Writer

type Enum

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

Enum represents a type-safe enumeration.

Declaration

To define an enum, declare an Enum type alias, an Enum struct and an initialized variable:

type HttpMethod = Enum[EnumHttpMethod]

type HttpMethodEnum struct {
	GET,
	HEAD,
	POST,
	PUT,
	PATCH,
	DELETE,
	CONNECT,
	OPTIONS,
	TRACE,
	USE HttpMethod
}

var HttpMethods = HttpMethod{}.New()

To access the enum values:

var method HttpMethod = HttpMethods.GET

Custom string serialization

Custom string serialization formats can be achieved by embedding an implementation of the EnumStringer interface. There is two implementations included : TitleEnumStringer or LowerEnumStringer.

type Protocol = Enum[ProtocolEnum]

type ProtocolEnum struct {
	LowerEnumStringer[ProtocolEnum]
	HTTP,
	HTTPS Protocol
}

var Protocols = Protocol{}.New()

Protocols.HTTPS.String() // will return "https".

--

To use zero-based ordinal values (e.g., 0, 1, 2) for serialization, add the `Enum:"Ordinal"` tag to the enum fields:

type IsSecure = Enum[IsSecureEnum]
type IsSecureEnum struct {
	UNSECURE,
	SECURE IsSecure `Enum:"Ordinal"`
}

Interfaces

As seen Enum implements the fmt.Stringer to return a string. But Enum implements a few other interfaces :

  • encoding.TextMarshaler & encoding.TextUnmarshaler : code/decode its name (or position if Ordinal) to []byte.
  • json.Marshaler & json.Unmarshaler : code/decode it to/from JSON.
  • sql.Scanner & driver.Valuer : to be used in a database model.

Because Enum[T] implements encoding.TextUnmarshaler, fields of custom enum types can be parsed directly in github.com/BeamFoundry/rays/pkg/core.ConfigurationProperties.

func (Enum[T]) Compare

func (this Enum[T]) Compare(that Enum[T]) int

Compare compares this Enum to another Enum of the same type. It returns a negative integer, zero, or a positive integer as this Enum's ordinal is less than, equal to, or greater than the compared Enum's ordinal.

func (*Enum[T]) From

func (this *Enum[T]) From(text string) error

From parses the given string and sets the enum to the matching value, returning an error if no match is found.

func (Enum[T]) MarshalJSON

func (this Enum[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It serializes the enum value to JSON, enclosing string representations in quotes or outputting raw numbers for ordinal enums.

func (Enum[T]) MarshalText

func (this Enum[T]) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It serializes the enum value to its string representation, or to its ordinal value if the enum is configured as ordinal.

func (Enum[T]) Name

func (this Enum[T]) Name() string

Name returns the raw field name of this enum value as defined in the container struct T.

func (Enum[T]) New

func (this Enum[T]) New() T

New initializes and returns the enum container T, establishing the internal ordinals and names for all of its Enum[T] fields. It should be treated as a constructor and must be called before using any of the Enum[T] members or methods.

func (Enum[T]) Ordinal

func (this Enum[T]) Ordinal() int

Ordinal returns the zero-based index of the enum value within the container T, excluding any fields that are not of type Enum[T].

func (*Enum[T]) Scan

func (this *Enum[T]) Scan(src any) error

Scan implements sql.Scanner, allowing database values to be scanned directly into the enum. It supports scanning from int64 for ordinal enums and string for name-based enums.

func (Enum[T]) String

func (this Enum[T]) String() string

String returns the string representation of the enum value. If the container struct T implements EnumStringer[T], it uses the customized format; otherwise, it returns the raw Name().

func (*Enum[T]) UnmarshalJSON

func (this *Enum[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It deserializes a JSON value into the enum value.

func (*Enum[T]) UnmarshalText

func (this *Enum[T]) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It parses the enum value from its text representation, supporting both string names (customized or raw) and ordinal values.

func (Enum[T]) Value

func (this Enum[T]) Value() (driver.Value, error)

Value implements driver.Valuer, returning the database value for this enum. It returns an int64 for ordinal enums and a string for name-based enums.

type EnumStringer

type EnumStringer[T comparable] interface {
	// ToString returns a custom string representation of the given enum value.
	ToString(Enum[T]) string
}

EnumStringer defines a custom formatting interface for enums. If the container struct T implements EnumStringer[T] (usually by embedding a struct that implements it, such as LowerEnumStringer or TitleEnumStringer), then String() will delegate to ToString to format the enum value name.

type Error

type Error interface {
	// Name() returns the error name.
	Name() string

	// Message() returns the error message.
	Message() string

	// Error() implements the error interface
	Error() string

	// AddAttribute() add attributes to the error to ge logged
	AddAttribute(key string, value any)

	// AddAttribute() add attributes to the error to ge logged
	AddAttributes(attr ...any)

	// Log() will log the error at the specified level, with optional arguments
	Log(level slog.Level, args ...any)

	// LogWithStackTrace() will log error with a stacktrace to its creation, with optional arguments.
	LogWithStackTrace(level slog.Level, args ...any)

	// LogError() will log the error at Error level, with optional arguments.
	LogError(args ...any)

	// LogErrorWithStackTrace() will log the error at Error level, wit hstacktrace and optional arguments
	LogErrorWithStackTrace(args ...any)

	// PrintStacktrace() will write the stacktrace on an [io.Writer]
	PrintStacktrace(out io.Writer)

	// Format() implements the [fmt.Formatter] interface.
	Format(state fmt.State, verb rune)

	// GomegaString() returns the error for Gomega
	GomegaString() string

	// MarshalJSON() will return a JSON version of this error.
	MarshalJSON() ([]byte, error)
}

Error is an interface representing an advanced error type, as it implements the [builtin.error] interface.

An Error has a name (like "IllegalArgumentError") and a message (ie. "You gave a wrong value of 'x' for the argument y.")

It can hold some attributes and be logged via the container logging engine.

It holds history of where it was created (frames), and produce a stacktrace, to be logged with the Error name and message.

There is default implementations like DefaultError and WrappedError, but you should use the functions NewError, NewErrorFrom or NewWrappedError to create one.

There is no need to have your own implementation, but it's open.

func NewErrorFrom

func NewErrorFrom(err error) Error

NewErrorFrom() creates a new WrappedError from an existing error.

The error name will be "WrappedError", and the error Error() as its message.

func NewWrappedError

func NewWrappedError(name string, err error, args ...any) Error

NewWrappedError returns an Error with a name from and error.

func Try

func Try(try func(), catches ...ErrorHandler) Error

Try() will execute a function try which may panic, resolving the different ErrorHandler defined and returning an Error if it occurred.

Note on Go Idioms: While using Try/Catch and panics for standard error handling is considered an anti-pattern in idiomatic Go (which heavily favors explicit `if err != nil` returns), this helper has its perks. It simplifies code that must catch unexpected runtime panics triggered underneath, without forcing the developer to rely on `recover()` directly, securely catching everything into a managed Error.

type ErrorHandler

type ErrorHandler interface {
	// Supports() returns whether can support handling err through Catch().
	//
	// Implementations should check err through [IsNilErr] and return false if that's the case.
	Supports(err Error) bool
	// Catch() will handle err. It may return nil, a new Error or the same, after for example using [Error.LogError].
	Catch(err Error) Error
}

ErrorHandler is an interface used by the Try() function as each clauses.

func Catch

func Catch[E Error](action func(E) Error) ErrorHandler

Catch() returns an ErrorHandler with an action for a typed Error E which will return an error or nil back as the Try return.

func CatchName

func CatchName(name string, action func(Error) Error) ErrorHandler

CatchName() returns an ErrorHandler with anction for a named Error which will return an error or nil back as the Try return.

func Finally

func Finally(action func()) ErrorHandler

Finally() returns an ErrorHandler which executes after, whatever the outcome.

Internally, its ErrorHandler.Supports method will return true only if its argument applied to IsNilError returns true, and its ErrorHandler.Catch method will run action, without regarding its argument.

That's the reason an ErrorHandler.Supports method must check for IsNilError.

type Exception

type Exception = Error

Aliasing Exception to Error. Can be used to indicate this Error should be handled with Try.

type FloatConstraint

type FloatConstraint interface {
	~float32 | ~float64
}

FloatConstraint is a constraint that permits any floating-point type. If future releases of Go add new predeclared floating-point types, this constraint will be modified to include them.

type IndexOutOfBoundsError

type IndexOutOfBoundsError struct {
	*DefaultError
}

IndexOutOfBoundsError represents a named Error for IndexOutOfBoundsError

func NewIndexOutOfBoundsError

func NewIndexOutOfBoundsError(message string) *IndexOutOfBoundsError

NewIndexOutOfBoundsError() creates a new IndexOutOfBoundsError with a message

type IntegerConstraint

type IntegerConstraint interface {
	SignedConstraint | UnsignedConstraint
}

IntegerConstraint is a constraint that permits any integer type. If future releases of Go add new predeclared integer types, this constraint will be modified to include them.

type LowerEnumStringer

type LowerEnumStringer[T comparable] struct{}

LowerEnumStringer is an implementation of EnumStringer[T] to have lower case name returned

func (LowerEnumStringer[T]) ToString

func (this LowerEnumStringer[T]) ToString(value Enum[T]) string

type NilError

type NilError struct{}

NilError represents an Error that will not log anything.

func (*NilError) AddAttribute

func (this *NilError) AddAttribute(_ string, _ any)

func (*NilError) AddAttributes

func (this *NilError) AddAttributes(_ ...any)

func (*NilError) Error

func (this *NilError) Error() string

func (*NilError) Format

func (this *NilError) Format(_ fmt.State, _ rune)

func (*NilError) GomegaString

func (this *NilError) GomegaString() string

func (*NilError) Log

func (this *NilError) Log(_ slog.Level, _ ...any)

func (*NilError) LogError

func (this *NilError) LogError(_ ...any)

func (*NilError) LogErrorWithStackTrace

func (this *NilError) LogErrorWithStackTrace(_ ...any)

func (*NilError) LogWithStackTrace

func (this *NilError) LogWithStackTrace(_ slog.Level, _ ...any)

func (*NilError) MarshalJSON

func (this *NilError) MarshalJSON() ([]byte, error)

func (*NilError) Message

func (this *NilError) Message() string

func (*NilError) Name

func (this *NilError) Name() string

func (*NilError) PrintStacktrace

func (this *NilError) PrintStacktrace(_ io.Writer)

type Optional

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

func OptionalEmpty

func OptionalEmpty[T any]() Optional[T]

OptionalEmpty() returns an empty Optional instance.

func OptionalOf

func OptionalOf[T any](value T) Optional[T]

OptionalOf() returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.

Contraty to OptionalOfNullable, this function will infere [T] from the argument "value".

As such this will not be accepted and produce a compile error :

value := OptionalOf[string](nil)

Passing a nil pointer will produce a OptionalEmpty.

var value *MyStruct = nil
opt := OptionalOf(value)
opt.IsPresent() // returns false

func OptionalOfNullable

func OptionalOfNullable[T any](value any) Optional[T]

OptionalOfNullable() returns an Optional[T] with the specified present non-nil value or an empty Optional.

Contrary to OptionalOf, this function needs the type to be specified, as the value argument is of type "any".

For example, this will be accepted and produce an OptionalEmpty[string]().

opt := OptionalOfNullable[string](nil)
opt.IsPresent() // returns false

Passing a nil pointer will produce a OptionalEmpty.

var value *MyStruct = nil
opt := OptionalOfNullable[*MyStruct](value)
opt.IsPresent() // returns false

func (Optional[T]) FlatMap

func (this Optional[T]) FlatMap(mapper func(T) Optional[T]) Optional[T]

FlatMap() if a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional.

func (Optional[T]) Get

func (this Optional[T]) Get() (T, bool)

Get() returns the value (or its zero value) and if it is present

func (Optional[T]) IfPresent

func (this Optional[T]) IfPresent(action func(T))

IfPresent() if a value is present, performs the given action with the value, otherwise does nothing.

func (Optional[T]) IfPresentOrElse

func (this Optional[T]) IfPresentOrElse(action func(T), empty func())

IfPresentOrElse() if a value is present, performs the given action with the value, otherwise performs the given empty-based action.

func (Optional[T]) IsEmpty

func (this Optional[T]) IsEmpty() bool

IsEmpty() if a value is not present, returns true, otherwise false.

func (Optional[T]) IsPresent

func (this Optional[T]) IsPresent() bool

IsPresent() if a value is present, returns true, otherwise false.

func (Optional[T]) Map

func (this Optional[T]) Map(mapper func(T) T) Optional[T]

Map() if a value is present, returns an Optional describing (as if by OptionalOfNullable the result of applying the given mapping function to the value, otherwise returns an empty Optional.

func (Optional[T]) OrElse

func (this Optional[T]) OrElse(other T) T

OrElse() if a value is present, returns the value, otherwise returns other.

func (Optional[T]) OrElseGet

func (this Optional[T]) OrElseGet(supplier func() T) T

OrElseGet() if a value is present returns the value, otherwise returns the value from the supplier function.

func (*Optional[T]) SetValue

func (this *Optional[T]) SetValue(value any) Error

SetValue() let's you set the value of T

func (Optional[T]) Type

func (this Optional[T]) Type() reflect.Type

Type() returns a reflect.Type of T

type OrderedConstraint

type OrderedConstraint interface {
	IntegerConstraint | FloatConstraint | ~string
}

OrderedConstraint is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.

type PanicError

type PanicError struct {
	*DefaultError
}

PanicError represents a named Error for PanicError

func NewPanicError

func NewPanicError(message string) *PanicError

NewPanicError() creates a new PanicError with a message

type PatternSyntaxError

type PatternSyntaxError struct {
	*DefaultError
}

PatternSyntaxError represents a named Error for PatternSyntaxError

func NewPatternSyntaxError

func NewPatternSyntaxError(message string) *PatternSyntaxError

NewPatternSyntaxError() creates a new PatternSyntaxError with a message

type SignedConstraint

type SignedConstraint interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

SignedConstraint is a constraint that permits any signed integer type. If future releases of Go add new predeclared signed integer types, this constraint will be modified to include them.

type String

type String string

func (String) Basename

func (this String) Basename() String

Basename returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Base returns a single separator.

func (String) CharAt

func (this String) CharAt(index int) (byte, Error)

CharAt returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

func (String) CodePointAt

func (this String) CodePointAt(index int) (rune, Error)

CodePointAt returns the rune value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

func (String) CompareTo

func (this String) CompareTo(a string) int

Compares two strings lexicographically. See Strings.Compare

func (String) Concat

func (this String) Concat(a string) String

Concatenates the specified string to the end of this String.

func (String) Contains

func (this String) Contains(a string) bool

Returns true if and only if this String contains the specified string.

func (String) EndsWith

func (this String) EndsWith(suffix string) bool

Tests if this string ends with the specified suffix.

func (String) Equals

func (this String) Equals(a string) bool

Compares this string to the specified String.

func (String) EqualsToIgnoreCase

func (this String) EqualsToIgnoreCase(a string) bool

Compares this String to another String, ignoring case considerations. See Strings.EqualFold.

func (String) Format

func (this String) Format(args ...any) String

Returns a formatted String using this String as the format and the arguments.

Example
fmt.Println(String("%s : %.2f").Format("Pi", 3.14159))
Output:
Pi : 3.14

func (String) GetBytes

func (this String) GetBytes() []byte

Convert this String to byte slice

func (String) IndexOf

func (this String) IndexOf(char rune) int

Returns the index within this String of the first occurrence of the specified character.

func (String) IsBlank

func (this String) IsBlank() bool

Returns true if the string is empty or contains only white space codepoints, otherwise false.

func (String) IsEmpty

func (this String) IsEmpty() bool

Returns true if, and only if, its length is 0.

func (String) Length

func (this String) Length() int

Returns the length of this String.

func (String) Matches

func (this String) Matches(regex string) (bool, Error)

Tells whether or not this String matches the given regular expression.

func (String) RegionMatches

func (this String) RegionMatches(ignoreCase bool, toffset int, other string, ooffset, length int) bool

func (String) Replace

func (this String) Replace(target, replacement string) String

Replaces each substring of this String that matches the literal target sequence with the specified literal replacement sequence.

func (String) ReplaceAll

func (this String) ReplaceAll(pattern, replacement string) (String, Error)

Replaces each substring of this String that matches the given regular expression with the given replacement.

func (String) ReplaceFirst

func (this String) ReplaceFirst(pattern, replacement string) (String, Error)

Replaces the first substring of this String that matches the given regular expression with the given replacement.

func (String) ReplaceRune

func (this String) ReplaceRune(oldChar, newChar rune) String

Returns a string resulting from replacing all occurrences of oldChar in this string with newChar.

func (String) Split

func (this String) Split(pattern string) ([]string, Error)

Splits this String around matches of the given regular expression.

func (String) SplitN

func (this String) SplitN(pattern string, limit int) ([]string, Error)

Splits this String around matches of the given regular expression.

func (String) StartsWith

func (this String) StartsWith(prefix string) bool

Tests if this String starts with the specified prefix.

func (String) String

func (this String) String() string

Implement Stringer interface to optain a string back from String

func (String) Strings

func (this String) Strings() Strings

Returns a Strings object from this String

func (String) Substring

func (this String) Substring(start int) String

Returns a String that is a substring of this string.

func (String) SubstringOffset

func (this String) SubstringOffset(start, end int) String

Returns a string that is a substring of this string.

func (String) ToCharArray

func (this String) ToCharArray() []rune

ToCharArray() returns a slice of rune.

func (String) ToLowerCase

func (this String) ToLowerCase() String

Converts all of the characters in this String to lower case.

func (String) ToUpperCase

func (this String) ToUpperCase() String

Converts all of the characters in this String to upper case.

func (String) Trim

func (this String) Trim() String

Returns a string whose value is this string, with all leading and trailing space removed, where space is defined as any character whose codepoint is less than or equal to 'U+0020' (the space character).

type Strings

type Strings string

func ToStrings

func ToStrings[S ByteStringConstraint](s S) Strings

func (Strings) Compare

func (s Strings) Compare(a string) int

Compare returns an integer comparing two strings lexicographically. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.

Compare is included only for symmetry with package bytes. It is usually clearer and always faster to use the built-in string comparison operators ==, <, >, and so on.

func (Strings) Contains

func (s Strings) Contains(substr string) bool

Contains reports whether substr is within s.

func (Strings) ContainsAny

func (s Strings) ContainsAny(chars string) bool

ContainsAny reports whether any Unicode code points in chars are within s.

func (Strings) ContainsFunc

func (s Strings) ContainsFunc(f func(rune) bool) bool

ContainsFunc reports whether any Unicode code points r within s satisfy f(r).

func (Strings) ContainsRune

func (s Strings) ContainsRune(r rune) bool

ContainsRune reports whether the Unicode code point r is within s.

func (Strings) Count

func (s Strings) Count(substr string) int

Count counts the number of non-overlapping instances of substr in s. If substr is an empty string, Count returns 1 + the number of Unicode code points in s.

func (Strings) Cut

func (s Strings) Cut(sep string) (before, after string, found bool)

Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false.

func (Strings) CutPrefix

func (s Strings) CutPrefix(prefix string) (after string, found bool)

CutPrefix returns s without the provided leading prefix string and reports whether it found the prefix. If s doesn't start with prefix, CutPrefix returns s, false. If prefix is the empty string, CutPrefix returns s, true.

func (Strings) CutSuffix

func (s Strings) CutSuffix(suffix string) (before string, found bool)

CutSuffix returns s without the provided ending suffix string and reports whether it found the suffix. If s doesn't end with suffix, CutSuffix returns s, false. If suffix is the empty string, CutSuffix returns s, true.

func (Strings) EqualFold

func (s Strings) EqualFold(t string) bool

EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under simple Unicode case-folding, which is a more general form of case-insensitivity.

func (Strings) Fields

func (s Strings) Fields() []string

Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space.

func (Strings) FieldsFunc

func (s Strings) FieldsFunc(f func(rune) bool) []string

FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) and returns an array of slices of s. If all code points in s satisfy f(c) or the string is empty, an empty slice is returned.

FieldsFunc makes no guarantees about the order in which it calls f(c) and assumes that f always returns the same value for a given c.

func (Strings) HasPrefix

func (s Strings) HasPrefix(prefix string) bool

HasPrefix tests whether the string s begins with prefix.

func (Strings) HasSuffix

func (s Strings) HasSuffix(suffix string) bool

HasSuffix tests whether the string s ends with suffix.

func (Strings) Index

func (s Strings) Index(substr string) int

Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.

func (Strings) IndexAny

func (s Strings) IndexAny(char string) int

IndexAny returns the index of the first instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

func (Strings) IndexByte

func (s Strings) IndexByte(c byte) int

IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.

func (Strings) IndexFunc

func (s Strings) IndexFunc(f func(rune) bool) int

IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.

func (Strings) IndexRune

func (s Strings) IndexRune(r rune) int

IndexRune returns the index of the first instance of the Unicode code point r, or -1 if rune is not present in s. If r is utf8.RuneError, it returns the first instance of any invalid UTF-8 byte sequence.

func (Strings) LastIndex

func (s Strings) LastIndex(substr string) int

LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.

func (Strings) LastIndexAny

func (s Strings) LastIndexAny(chars string) int

LastIndexAny returns the index of the last instance of any Unicode code point from chars in s, or -1 if no Unicode code point from chars is present in s.

func (Strings) LastIndexByte

func (s Strings) LastIndexByte(c byte) int

LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.

func (Strings) LastIndexFunc

func (s Strings) LastIndexFunc(f func(rune) bool) int

LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.

func (Strings) Map

func (s Strings) Map(mapping func(rune) rune) string

Map returns a copy of the string s with all its characters modified according to the mapping function. If mapping returns a negative value, the character is dropped from the string with no replacement.

func (Strings) Repeat

func (s Strings) Repeat(count int) string

Repeat returns a new string consisting of count copies of the string s.

It panics if count is negative or if the result of (len(s) * count) overflows.

func (Strings) Replace

func (s Strings) Replace(old, replacement string, n int) string

Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements.

func (Strings) ReplaceAll

func (s Strings) ReplaceAll(old, replacement string) string

ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string.

func (Strings) Split

func (s Strings) Split(sep string) []string

Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators.

If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s.

If sep is empty, Split splits after each UTF-8 sequence. If both s and sep are empty, Split returns an empty slice.

It is equivalent to SplitN with a count of -1.

To split around the first instance of a separator, see Cut.

func (Strings) SplitAfter

func (s Strings) SplitAfter(sep string) []string

SplitAfter slices s into all substrings after each instance of sep and returns a slice of those substrings.

If s does not contain sep and sep is not empty, SplitAfter returns a slice of length 1 whose only element is s.

If sep is empty, SplitAfter splits after each UTF-8 sequence. If both s and sep are empty, SplitAfter returns an empty slice.

It is equivalent to SplitAfterN with a count of -1.

func (Strings) SplitAfterN

func (s Strings) SplitAfterN(sep string, n int) []string

SplitAfterN slices s into substrings after each instance of sep and returns a slice of those substrings.

func (Strings) SplitN

func (s Strings) SplitN(sep string, n int) []string

SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.

func (Strings) String

func (s Strings) String() string

func (Strings) ToLower

func (s Strings) ToLower() string

ToLower returns s with all Unicode letters mapped to their lower case.

func (Strings) ToLowerSpecial

func (s Strings) ToLowerSpecial(c unicode.SpecialCase) string

ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their lower case using the case mapping specified by c.

func (Strings) ToString

func (s Strings) ToString() String

func (Strings) ToUpper

func (s Strings) ToUpper() string

ToUpper returns s with all Unicode letters mapped to their upper case.

func (Strings) ToUpperSpecial

func (s Strings) ToUpperSpecial(c unicode.SpecialCase) string

ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their upper case using the case mapping specified by c.

func (Strings) ToValidUTF8

func (s Strings) ToValidUTF8(replacement string) string

ToValidUTF8 returns a copy of the string s with each run of invalid UTF-8 byte sequences replaced by the replacement string, which may be empty.

func (Strings) Trim

func (s Strings) Trim(cutset string) string

Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.

func (Strings) TrimFunc

func (s Strings) TrimFunc(f func(rune) bool) string

TrimFunc returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed.

func (Strings) TrimLeft

func (s Strings) TrimLeft(cutset string) string

TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.

func (Strings) TrimLeftFunc

func (s Strings) TrimLeftFunc(f func(rune) bool) string

TrimLeftFunc returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed.

func (Strings) TrimPrefix

func (s Strings) TrimPrefix(prefix string) string

TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.

func (Strings) TrimRight

func (s Strings) TrimRight(cutset string) string

TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

func (Strings) TrimRightFunc

func (s Strings) TrimRightFunc(f func(rune) bool) string

TrimRightFunc returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed.

func (Strings) TrimSpace

func (s Strings) TrimSpace() string

TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

func (Strings) TrimSuffix

func (s Strings) TrimSuffix(suffix string) string

TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.

type TitleEnumStringer

type TitleEnumStringer[T comparable] struct{}

TitleEnumStringer is an implementation of EnumStringer[T] to have the title case name returned.

func (TitleEnumStringer[T]) ToString

func (this TitleEnumStringer[T]) ToString(value Enum[T]) string

type UnsignedConstraint

type UnsignedConstraint interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

UnsignedConstraint is a constraint that permits any unsigned integer type. If future releases of Go add new predeclared unsigned integer types, this constraint will be modified to include them.

type WrappedError

type WrappedError struct {
	*DefaultError
	// contains filtered or unexported fields
}

WrappedError is a structure permitting to wrap an error as an Error.

func (*WrappedError) Unwrap

func (this *WrappedError) Unwrap() error

Unwrap() returns the wrapped error.

Jump to

Keyboard shortcuts

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