Documentation
¶
Index ¶
- func IsNilError[T Error](err T) bool
- func RaiseErr(err error) bool
- func RaiseNilErr(err error) bool
- func RaiseVal[T any](t T, e error) T
- type ByteStringConstraint
- type ComplexConstraint
- type DefaultError
- func (this *DefaultError) AddAttribute(key string, value any)
- func (this *DefaultError) AddAttributes(attr ...any)
- func (this *DefaultError) Error() string
- func (this *DefaultError) Format(state fmt.State, verb rune)
- func (this *DefaultError) GomegaString() string
- func (this *DefaultError) Log(level slog.Level, args ...any)
- func (this *DefaultError) LogError(args ...any)
- func (this *DefaultError) LogErrorWithStackTrace(args ...any)
- func (this *DefaultError) LogWithStackTrace(level slog.Level, args ...any)
- func (this *DefaultError) MarshalJSON() ([]byte, error)
- func (this *DefaultError) Message() string
- func (this *DefaultError) Name() string
- func (this *DefaultError) PrintStacktrace(out io.Writer)
- type Enum
- func (this Enum[T]) Compare(that Enum[T]) int
- func (this *Enum[T]) From(text string) error
- func (this Enum[T]) MarshalJSON() ([]byte, error)
- func (this Enum[T]) MarshalText() ([]byte, error)
- func (this Enum[T]) Name() string
- func (this Enum[T]) New() T
- func (this Enum[T]) Ordinal() int
- func (this *Enum[T]) Scan(src any) error
- func (this Enum[T]) String() string
- func (this *Enum[T]) UnmarshalJSON(data []byte) error
- func (this *Enum[T]) UnmarshalText(text []byte) error
- func (this Enum[T]) Value() (driver.Value, error)
- type EnumStringer
- type Error
- type ErrorHandler
- type Exception
- type FloatConstraint
- type IndexOutOfBoundsError
- type IntegerConstraint
- type LowerEnumStringer
- type NilError
- func (this *NilError) AddAttribute(_ string, _ any)
- func (this *NilError) AddAttributes(_ ...any)
- func (this *NilError) Error() string
- func (this *NilError) Format(_ fmt.State, _ rune)
- func (this *NilError) GomegaString() string
- func (this *NilError) Log(_ slog.Level, _ ...any)
- func (this *NilError) LogError(_ ...any)
- func (this *NilError) LogErrorWithStackTrace(_ ...any)
- func (this *NilError) LogWithStackTrace(_ slog.Level, _ ...any)
- func (this *NilError) MarshalJSON() ([]byte, error)
- func (this *NilError) Message() string
- func (this *NilError) Name() string
- func (this *NilError) PrintStacktrace(_ io.Writer)
- type Optional
- func (this Optional[T]) FlatMap(mapper func(T) Optional[T]) Optional[T]
- func (this Optional[T]) Get() (T, bool)
- func (this Optional[T]) IfPresent(action func(T))
- func (this Optional[T]) IfPresentOrElse(action func(T), empty func())
- func (this Optional[T]) IsEmpty() bool
- func (this Optional[T]) IsPresent() bool
- func (this Optional[T]) Map(mapper func(T) T) Optional[T]
- func (this Optional[T]) OrElse(other T) T
- func (this Optional[T]) OrElseGet(supplier func() T) T
- func (this *Optional[T]) SetValue(value any) Error
- func (this Optional[T]) Type() reflect.Type
- type OrderedConstraint
- type PanicError
- type PatternSyntaxError
- type SignedConstraint
- type String
- func (this String) Basename() String
- func (this String) CharAt(index int) (byte, Error)
- func (this String) CodePointAt(index int) (rune, Error)
- func (this String) CompareTo(a string) int
- func (this String) Concat(a string) String
- func (this String) Contains(a string) bool
- func (this String) EndsWith(suffix string) bool
- func (this String) Equals(a string) bool
- func (this String) EqualsToIgnoreCase(a string) bool
- func (this String) Format(args ...any) String
- func (this String) GetBytes() []byte
- func (this String) IndexOf(char rune) int
- func (this String) IsBlank() bool
- func (this String) IsEmpty() bool
- func (this String) Length() int
- func (this String) Matches(regex string) (bool, Error)
- func (this String) RegionMatches(ignoreCase bool, toffset int, other string, ooffset, length int) bool
- func (this String) Replace(target, replacement string) String
- func (this String) ReplaceAll(pattern, replacement string) (String, Error)
- func (this String) ReplaceFirst(pattern, replacement string) (String, Error)
- func (this String) ReplaceRune(oldChar, newChar rune) String
- func (this String) Split(pattern string) ([]string, Error)
- func (this String) SplitN(pattern string, limit int) ([]string, Error)
- func (this String) StartsWith(prefix string) bool
- func (this String) String() string
- func (this String) Strings() Strings
- func (this String) Substring(start int) String
- func (this String) SubstringOffset(start, end int) String
- func (this String) ToCharArray() []rune
- func (this String) ToLowerCase() String
- func (this String) ToUpperCase() String
- func (this String) Trim() String
- type Strings
- func (s Strings) Compare(a string) int
- func (s Strings) Contains(substr string) bool
- func (s Strings) ContainsAny(chars string) bool
- func (s Strings) ContainsFunc(f func(rune) bool) bool
- func (s Strings) ContainsRune(r rune) bool
- func (s Strings) Count(substr string) int
- func (s Strings) Cut(sep string) (before, after string, found bool)
- func (s Strings) CutPrefix(prefix string) (after string, found bool)
- func (s Strings) CutSuffix(suffix string) (before string, found bool)
- func (s Strings) EqualFold(t string) bool
- func (s Strings) Fields() []string
- func (s Strings) FieldsFunc(f func(rune) bool) []string
- func (s Strings) HasPrefix(prefix string) bool
- func (s Strings) HasSuffix(suffix string) bool
- func (s Strings) Index(substr string) int
- func (s Strings) IndexAny(char string) int
- func (s Strings) IndexByte(c byte) int
- func (s Strings) IndexFunc(f func(rune) bool) int
- func (s Strings) IndexRune(r rune) int
- func (s Strings) LastIndex(substr string) int
- func (s Strings) LastIndexAny(chars string) int
- func (s Strings) LastIndexByte(c byte) int
- func (s Strings) LastIndexFunc(f func(rune) bool) int
- func (s Strings) Map(mapping func(rune) rune) string
- func (s Strings) Repeat(count int) string
- func (s Strings) Replace(old, replacement string, n int) string
- func (s Strings) ReplaceAll(old, replacement string) string
- func (s Strings) Split(sep string) []string
- func (s Strings) SplitAfter(sep string) []string
- func (s Strings) SplitAfterN(sep string, n int) []string
- func (s Strings) SplitN(sep string, n int) []string
- func (s Strings) String() string
- func (s Strings) ToLower() string
- func (s Strings) ToLowerSpecial(c unicode.SpecialCase) string
- func (s Strings) ToString() String
- func (s Strings) ToUpper() string
- func (s Strings) ToUpperSpecial(c unicode.SpecialCase) string
- func (s Strings) ToValidUTF8(replacement string) string
- func (s Strings) Trim(cutset string) string
- func (s Strings) TrimFunc(f func(rune) bool) string
- func (s Strings) TrimLeft(cutset string) string
- func (s Strings) TrimLeftFunc(f func(rune) bool) string
- func (s Strings) TrimPrefix(prefix string) string
- func (s Strings) TrimRight(cutset string) string
- func (s Strings) TrimRightFunc(f func(rune) bool) string
- func (s Strings) TrimSpace() string
- func (s Strings) TrimSuffix(suffix string) string
- type TitleEnumStringer
- type UnsignedConstraint
- type WrappedError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNilError ¶
IsNilError will return if an Error is nil or not.
func RaiseErr ¶
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 ¶
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.
Types ¶
type ByteStringConstraint ¶
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) 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
UnmarshalJSON implements json.Unmarshaler. It deserializes a JSON value into the enum value.
func (*Enum[T]) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It parses the enum value from its text representation, supporting both string names (customized or raw) and ordinal values.
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 ¶
NewErrorFrom() creates a new WrappedError from an existing error.
The error name will be "WrappedError", and the error Error() as its message.
func NewWrappedError ¶
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 ¶
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 (*NilError) AddAttributes ¶
func (*NilError) GomegaString ¶
func (*NilError) LogErrorWithStackTrace ¶
func (*NilError) LogWithStackTrace ¶
func (*NilError) MarshalJSON ¶
func (*NilError) PrintStacktrace ¶
type Optional ¶
type Optional[T any] struct { // contains filtered or unexported fields }
func OptionalEmpty ¶
OptionalEmpty() returns an empty Optional instance.
func OptionalOf ¶
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 ¶
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 ¶
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]) 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]) Map ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Compares two strings lexicographically. See Strings.Compare
func (String) EqualsToIgnoreCase ¶
Compares this String to another String, ignoring case considerations. See Strings.EqualFold.
func (String) Format ¶
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) IndexOf ¶
Returns the index within this String of the first occurrence of the specified character.
func (String) IsBlank ¶
Returns true if the string is empty or contains only white space codepoints, otherwise false.
func (String) RegionMatches ¶
func (String) Replace ¶
Replaces each substring of this String that matches the literal target sequence with the specified literal replacement sequence.
func (String) ReplaceAll ¶
Replaces each substring of this String that matches the given regular expression with the given replacement.
func (String) ReplaceFirst ¶
Replaces the first substring of this String that matches the given regular expression with the given replacement.
func (String) ReplaceRune ¶
Returns a string resulting from replacing all occurrences of oldChar in this string with newChar.
func (String) StartsWith ¶
Tests if this String starts with the specified prefix.
func (String) SubstringOffset ¶
Returns a string that is a substring of this string.
func (String) ToCharArray ¶
ToCharArray() returns a slice of rune.
func (String) ToLowerCase ¶
Converts all of the characters in this String to lower case.
func (String) ToUpperCase ¶
Converts all of the characters in this String to upper case.
type Strings ¶
type Strings string
func ToStrings ¶
func ToStrings[S ByteStringConstraint](s S) Strings
func (Strings) Compare ¶
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) ContainsAny ¶
ContainsAny reports whether any Unicode code points in chars are within s.
func (Strings) ContainsFunc ¶
ContainsFunc reports whether any Unicode code points r within s satisfy f(r).
func (Strings) ContainsRune ¶
ContainsRune reports whether the Unicode code point r is within s.
func (Strings) Count ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) Index ¶
Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.
func (Strings) IndexAny ¶
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 ¶
IndexByte returns the index of the first instance of c in s, or -1 if c is not present in s.
func (Strings) IndexFunc ¶
IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.
func (Strings) IndexRune ¶
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 ¶
LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
func (Strings) LastIndexAny ¶
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 ¶
LastIndexByte returns the index of the last instance of c in s, or -1 if c is not present in s.
func (Strings) LastIndexFunc ¶
LastIndexFunc returns the index into s of the last Unicode code point satisfying f(c), or -1 if none do.
func (Strings) Map ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SplitAfterN slices s into substrings after each instance of sep and returns a slice of those substrings.
func (Strings) SplitN ¶
SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.
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) 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 ¶
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 ¶
Trim returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed.
func (Strings) TrimFunc ¶
TrimFunc returns a slice of the string s with all leading and trailing Unicode code points c satisfying f(c) removed.
func (Strings) TrimLeft ¶
TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.
func (Strings) TrimLeftFunc ¶
TrimLeftFunc returns a slice of the string s with all leading Unicode code points c satisfying f(c) removed.
func (Strings) TrimPrefix ¶
TrimPrefix returns s without the provided leading prefix string. If s doesn't start with prefix, s is returned unchanged.
func (Strings) TrimRight ¶
TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.
func (Strings) TrimRightFunc ¶
TrimRightFunc returns a slice of the string s with all trailing Unicode code points c satisfying f(c) removed.
func (Strings) TrimSpace ¶
TrimSpace returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.
func (Strings) TrimSuffix ¶
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 ¶
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.