Skip to content

Commit a359c9e

Browse files
committed
add match package import rule
1 parent cbc67ff commit a359c9e

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Match package import in Golang
2+
3+
* [Playground Link](/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImdvIiwicXVlcnkiOiJhd2FpdCAkQSIsInJld3JpdGUiOiJ0cnkge1xuICAgIGF3YWl0ICRBXG59IGNhdGNoKGUpIHtcbiAgICAvLyB0b2RvXG59Iiwic3RyaWN0bmVzcyI6InNtYXJ0Iiwic2VsZWN0b3IiOiIiLCJjb25maWciOiJpZDogbWF0Y2gtaW1wb3J0LXBrZ1xubGFuZ3VhZ2U6IGdvXG5ydWxlOlxuICBraW5kOiBpbXBvcnRfc3BlY1xuICBoYXM6XG4gICAgcmVnZXg6IGdpdGh1Yi5jb20vZ29sYW5nLWp3dC9qd3QiLCJzb3VyY2UiOiJpbXBvcnQgKFxuXHRcImNvbnRleHRcIlxuXHRcImZtdFwiXG5cdFwib3NcIlxuXG5cdFwiZ2l0aHViLmNvbS9nb2xhbmctand0L2p3dFwiXG4pXG5cbmltcG9ydCBcdFwiZ2l0aHViLmNvbS9nb2xhbmctand0L2p3dFwiIn0=)
4+
5+
### Description
6+
7+
A generic rule template for detecting imports of specific packages in Go source code. This rule can be customized to match any package by modifying the regex pattern, making it useful for security auditing, dependency management, and compliance checking.
8+
9+
### YAML
10+
11+
```yaml
12+
id: match-package-import
13+
language: go
14+
rule:
15+
kind: import_spec
16+
has:
17+
regex: PACKAGE_PATTERN_HERE
18+
```
19+
20+
### Configuration
21+
Replace PACKAGE_PATTERN_HERE with your target package pattern
22+
23+
### What it matches
24+
25+
This rule identifies Go import statements based on the configured regex pattern, including:
26+
27+
Direct imports: `import "package/name"`
28+
Versioned imports: `import "package/name/v4"`
29+
Subpackage imports: `import "package/name/subpkg"`
30+
Grouped imports within `import () blocks`
31+
32+
### Example
33+
34+
JWT Library Detection
35+
36+
```go{2}
37+
id: match-package-import
38+
language: go
39+
rule:
40+
kind: import_spec
41+
has:
42+
regex: github.com/golang-jwt/jwt
43+
```
44+
45+
### Contributed by
46+
[Sudesh Gutta](https://github.com/sudeshgutta)

0 commit comments

Comments
 (0)