From 55e928d3cfe7f204fb5c19abfb0a53ca3b0ec00e Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sun, 5 Nov 2023 00:23:40 -0700 Subject: [PATCH] initial commits --- errors/errors.go | 19 +++++++++++++++++++ number/number.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 errors/errors.go create mode 100644 number/number.go diff --git a/errors/errors.go b/errors/errors.go new file mode 100644 index 0000000..22819d6 --- /dev/null +++ b/errors/errors.go @@ -0,0 +1,19 @@ +package rfc8259errors + +import ( + "sourcecode.social/reiver/go-erorr" +) + +const ( + ErrNilDestination = erorr.Error("rfc8259: nil destination") + ErrNilRuneScanner = erorr.Error("rfc8259: nil rune-scanner") + ErrUnexpectedEndOfFile = erorr.Error("rfc8259: unexpected end-of-file") +) + +func ErrProblemReadingRune(err error) error { + return erorr.Errorf("rfc8259: JSON parser had a problem — problem reading rune: %w", err) +} + +func ErrProblemUnreadingRune(err error, r rune) error { + return erorr.Errorf("rfc8259: JSON parser had an internal-error — problem unreading rune %q (%U): %w", r, r, err) +} diff --git a/number/number.go b/number/number.go new file mode 100644 index 0000000..87c5fdb --- /dev/null +++ b/number/number.go @@ -0,0 +1,32 @@ +package rfc8259number + +import ( + "fmt" + + "sourcecode.social/reiver/go-opt" +) + +type Number struct { + opt.Optional[string] +} + +func Nothing() Number { + return Number{opt.Nothing[string]()} +} + +func Something(value string) Number { + return Number{opt.Something(value)} +} + +func (receiver Number) GoString() string { + switch receiver { + case Nothing(): + return "rfc8259number.Nothing()" + default: + value, found := receiver.Get() + if !found { + return fmt.Sprintf("--INTERNAL-ERROR--") + } + return fmt.Sprintf("rfc8259number.Something(%#v)", value) + } +}