MCPcopy
hub / github.com/gofiber/fiber / Convert

Function Convert

helpers.go:969–980  ·  view source on GitHub ↗

Convert a string value to a specified type, handling errors and optional default values.

(value string, converter func(string) (T, error), defaultValue ...T)

Source from the content-addressed store, hash-verified

967
968// Convert a string value to a specified type, handling errors and optional default values.
969func Convert[T any](value string, converter func(string) (T, error), defaultValue ...T) (T, error) {
970 converted, err := converter(value)
971 if err != nil {
972 if len(defaultValue) > 0 {
973 return defaultValue[0], nil
974 }
975
976 return converted, fmt.Errorf("failed to convert: %w", err)
977 }
978
979 return converted, nil
980}
981
982var (
983 errParsedEmptyString = errors.New("parsed result is empty string")

Callers

nothing calls this directly

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected