Skip to content

Commit 8adb51e

Browse files
committed
Update README
Signed-off-by: Philippe Ombredanne <pombredanne@aboutcode.org>
1 parent e0b5077 commit 8adb51e

1 file changed

Lines changed: 52 additions & 27 deletions

File tree

README.md

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,87 @@
66

77
**purlvalidator** is a Go library for validating [Package-URLs (PURLs)](https://github.com/package-url/purl-spec). It works fully offline, including in **air-gapped** or **restricted environments**, and answers one key question: **Does the package this PURL represents actually exist?**
88

9-
## How It Works?
9+
## How It Works
1010

1111
**purlvalidator** is shipped with a pre-built FST (Finite State Transducer), a set of compact automata containing latest Package-URLs mined by the MineCode[^1]. Library uses this FST to perform lookups and confirm whether the **base PURL**[^2] exists.
1212

1313
## Currently Supported Ecosystems
1414

15-
- **apk**
16-
- **cargo**
17-
- **composer**
18-
- **conan**
19-
- **cpan**
20-
- **cran**
21-
- **debain**
22-
- **maven**
23-
- **npm**
24-
- **nuget**
25-
- **pypi**
26-
- **swift**
15+
- apk
16+
- cargo
17+
- composer
18+
- conan
19+
- cpan
20+
- cran
21+
- debian
22+
- maven
23+
- npm
24+
- nuget
25+
- pypi
26+
- swift
2727

2828
## Usage
2929

30-
Add `purlvalidator` as dependency in your go.mod
30+
Add `purlvalidator` as a dependency:
3131

3232
```bash
33+
go get github.com/aboutcode-org/purlvalidator-go
34+
```
35+
36+
Or add it to `go.mod`:
37+
38+
```text
3339
require github.com/aboutcode-org/purlvalidator-go v1.0.0
3440
```
3541

3642
Use it in your code like this:
3743

3844
```go
39-
import "github.com/aboutcode-org/purlvalidator-go"
45+
package main
46+
47+
import (
48+
"fmt"
49+
"log"
50+
51+
purlvalidator "github.com/aboutcode-org/purlvalidator-go"
52+
)
4053

4154
func main() {
42-
result, e := purlvalidator.Validate("pkg:nuget/FluentValidation");
55+
exists, err := purlvalidator.Validate("pkg:nuget/FluentValidation")
4356
if err != nil {
44-
panic(err)
57+
log.Fatal(err)
4558
}
59+
60+
fmt.Println(exists)
4661
}
4762
```
4863

4964
Examples and errors:
65+
5066
```go
51-
// This will return: true
52-
purlvalidator.Validate("pkg:nuget/FluentValidation");
67+
exists, err := purlvalidator.Validate("pkg:nuget/FluentValidation")
68+
// exists == true, err == nil
69+
70+
exists, err = purlvalidator.Validate("pkg:nuget/non-existent-foo-bar")
71+
// exists == false, err == nil
5372

54-
// This will return: false
55-
purlvalidator.Validate("pkg:nuget/non-existent-foo-bar");
73+
exists, err = purlvalidator.Validate("pkg:nuget/FluentValidation@10.2.3")
74+
// err reports that only base PURLs are supported.
5675

76+
exists, err = purlvalidator.Validate("test:nuget/FluentValidation")
77+
// err reports that the PURL scheme is invalid.
78+
```
5779

58-
// This will return an error: "only base PURL is supported (no version, qualifiers, or subpath)"
59-
purlvalidator.Validate("pkg:nuget/FluentValidation@10.2.3");
80+
`Validate` returns:
6081

61-
// This will return an error: "purl scheme is not \"pkg\": \"test\""
62-
purlvalidator.Validate("test:nuget/FluentValidation");
82+
- `true, nil` when the base PURL exists in the packaged data.
83+
- `false, nil` when the base PURL is syntactically valid but unknown.
84+
- `false, err` when the input is not a valid PURL or contains a version,
85+
qualifiers, or subpath.
86+
87+
Use the released module version when you need reproducible validation results.
88+
Use a newer patch release when you need newer packaged PURL data.
6389

64-
```
6590

6691
## How to get latest Package-URL data?
6792

@@ -117,4 +142,4 @@ limitations under the License.
117142
```
118143

119144
[^1]: MineCode continuously collects package metadata from various package ecosystems to maintain an up-to-date catalog of known packages.
120-
[^2]: A Base Package-URL is a Package-URL without a version, qualifiers or subpath.
145+
[^2]: A Base Package-URL is a Package-URL without a version, qualifiers, or subpath.

0 commit comments

Comments
 (0)