From 6abc522a229c7b3414655787b857ca5ab5c3a3bb Mon Sep 17 00:00:00 2001 From: Caio Ferreira Date: Wed, 17 Apr 2024 18:26:15 -0300 Subject: [PATCH] chore: add go doc Signed-off-by: Caio Ferreira --- value.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/value.go b/value.go index 62752259..e0013d08 100644 --- a/value.go +++ b/value.go @@ -405,6 +405,10 @@ type Decimal int64 // DecimalPrecision is the precision of a Decimal. const DecimalPrecision = 10000 +// ParseDecimal takes a string representation of a decimal number and converts it into a Decimal type. +// The function handles optional negative sign and ensures that the decimal part of the number does not exceed four digits. +// It returns an error if the string is empty, contains non-digit characters, missing decimal point, or if the number overflows. +// The function also handles the case of negative numbers correctly to avoid overflow. func ParseDecimal(s string) (Decimal, error) { // Check for empty string. if len(s) == 0 { @@ -576,6 +580,10 @@ func (v Decimal) deepClone() Value { return v } // The value can represent an individual address or a range of addresses. type IPAddr netip.Prefix +// ParseIPAddr takes a string representation of an IP address and converts it into an IPAddr type. +// The function handles both IPv4 and IPv6 addresses, and can also handle IP ranges. +// It disallows IPv4-mapped IPv6 addresses in dotted notation. +// The function returns an error if the string cannot be parsed into an IP address or IP range. func ParseIPAddr(s string) (IPAddr, error) { // We disallow IPv4-mapped IPv6 addresses in dotted notation because Cedar does. if strings.Count(s, ":") >= 2 && strings.Count(s, ".") >= 2 {