google / uuid

Go package for UUIDs based on RFC 4122 and DCE 1.1: Authentication and Security Services.
BSD 3-Clause "New" or "Revised" License
5.16k stars 362 forks source link

feat: Validate UUID without creating new UUID #141

Closed ljahier closed 7 months ago

ljahier commented 7 months ago

Overview

This pull request introduces a new function, Validate(s string) error, in response to the request in issue #137. The primary goal is to provide a way to validate UUID strings without the overhead of creating a UUID object and its underlying byte array, as currently happens in the Parse(s string) (UUID, error) function.

Changes Made

Rationale

This change is particularly useful in scenarios where UUIDs are frequently validated but not used in their byte form. It optimizes performance by eliminating unnecessary memory allocations associated with UUID object creation, especially in high-throughput environments.

Testing

Unit tests have been added to cover various cases:

The tests ensure that the new validation function behaves as expected across a wide range of valid and invalid inputs.

Impact

This update introduces a non-breaking change, adding new functionality to the library without altering existing behaviors.

Looking forward to your feedback and suggestions on this implementation!

Resolves #137

google-cla[bot] commented 7 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.