Skip to content

Commit

Permalink
chore: add go doc
Browse files Browse the repository at this point in the history
Signed-off-by: Caio Ferreira <[email protected]>
  • Loading branch information
Caio Ferreira committed Apr 17, 2024
1 parent f6c68cc commit 6abc522
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6abc522

Please sign in to comment.