Documentation
¶
Overview ¶
Example ¶
Example demonstrates marshaling results to JSON
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/scanoss/scanoss.go/pkg/dependencies"
"github.com/scanoss/scanoss.go/pkg/dependencies/parsers"
)
func main() {
parser := dependencies.NewDependencyParser()
// Simulated result
result := &parsers.LocalDependencies{
Files: []parsers.LocalDependency{
{
File: "go.mod",
Purls: []parsers.LocalPurl{
{
Purl: "pkg:golang/github.com/spf13/cobra@v1.10.2",
Requirement: "v1.10.2",
},
},
},
},
}
// Note: In actual code, you would get this from parser.ParseFiles()
_ = parser
jsonData, err := json.MarshalIndent(result, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(jsonData))
}
Output: { "files": [ { "file": "go.mod", "purls": [ { "purl": "pkg:golang/github.com/spf13/cobra@v1.10.2", "requirement": "v1.10.2" } ] } ] }
Index ¶
- type DependencyParser
- func (dp *DependencyParser) FilterFiles(files []string) []string
- func (dp *DependencyParser) GetParserFunc(filePath string) (parsers.ParserFunc, bool)
- func (dp *DependencyParser) IsSupportedFile(filePath string) bool
- func (dp *DependencyParser) ParseFile(filePath string) (*parsers.LocalDependency, error)
- func (dp *DependencyParser) ParseFiles(files []string) (*parsers.LocalDependencies, error)
- func (dp *DependencyParser) SupportedFiles() []string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DependencyParser ¶
type DependencyParser struct {
// contains filtered or unexported fields
}
DependencyParser orchestrates parsing of dependency files across different ecosystems
func NewDependencyParser ¶
func NewDependencyParser() *DependencyParser
NewDependencyParser creates a new instance of DependencyParser with all supported parsers
func (*DependencyParser) FilterFiles ¶
func (dp *DependencyParser) FilterFiles(files []string) []string
FilterFiles returns only files that have a registered parser
Example ¶
package main
import (
"fmt"
"github.com/scanoss/scanoss.go/pkg/dependencies"
)
func main() {
parser := dependencies.NewDependencyParser()
files := []string{
"README.md",
"package.json",
"go.mod",
"main.go",
"pom.xml",
"requirements.txt",
}
supported := parser.FilterFiles(files)
fmt.Printf("Found %d supported dependency files\n", len(supported))
}
Output: Found 4 supported dependency files
func (*DependencyParser) GetParserFunc ¶
func (dp *DependencyParser) GetParserFunc(filePath string) (parsers.ParserFunc, bool)
GetParserFunc returns the appropriate parser function for a given file
func (*DependencyParser) IsSupportedFile ¶
func (dp *DependencyParser) IsSupportedFile(filePath string) bool
IsSupportedFile checks if a file is supported by any parser
Example ¶
package main
import (
"fmt"
"github.com/scanoss/scanoss.go/pkg/dependencies"
)
func main() {
parser := dependencies.NewDependencyParser()
files := map[string]bool{
"package.json": true,
"go.mod": true,
"main.go": false,
"requirements.txt": true,
"pom.xml": true,
"README.md": false,
}
for file, expectedSupport := range files {
isSupported := parser.IsSupportedFile(file)
if isSupported == expectedSupport {
fmt.Printf("%s: supported=%v\n", file, isSupported)
}
}
// Output will vary based on execution order, but all files will be checked
}
Output:
func (*DependencyParser) ParseFile ¶
func (dp *DependencyParser) ParseFile(filePath string) (*parsers.LocalDependency, error)
ParseFile parses a single dependency file and returns the extracted dependencies
Example ¶
package main
import (
"fmt"
"github.com/scanoss/scanoss.go/pkg/dependencies"
)
func main() {
parser := dependencies.NewDependencyParser()
// In real usage, you would parse from a file:
// result, err := parser.ParseFile("path/to/go.mod")
// if err != nil {
// log.Fatal(err)
// }
// For this example, just demonstrate parser creation
_ = parser // placeholder for example
fmt.Println("Parser created successfully")
}
Output: Parser created successfully
func (*DependencyParser) ParseFiles ¶
func (dp *DependencyParser) ParseFiles(files []string) (*parsers.LocalDependencies, error)
ParseFiles parses multiple dependency files and returns aggregated results
func (*DependencyParser) SupportedFiles ¶
func (dp *DependencyParser) SupportedFiles() []string
SupportedFiles returns a list of all supported dependency file patterns
Example ¶
package main
import (
"fmt"
"github.com/scanoss/scanoss.go/pkg/dependencies"
)
func main() {
parser := dependencies.NewDependencyParser()
patterns := parser.SupportedFiles()
fmt.Printf("Total supported patterns: %d\n", len(patterns))
fmt.Println("Includes patterns for Node.js, Python, Java, Go, Ruby, and .NET")
}
Output: Total supported patterns: 13 Includes patterns for Node.js, Python, Java, Go, Ruby, and .NET
Directories
¶
| Path | Synopsis |
|---|---|
|
Package parsers provides functionality to parse dependency manifests from various package management systems and extract dependency information as standardized Package URLs (PURLs).
|
Package parsers provides functionality to parse dependency manifests from various package management systems and extract dependency information as standardized Package URLs (PURLs). |