forked from aboutcode-org/go-inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3530fb
commit 4fc9874
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package goInspector | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/goretk/gore" | ||
"path/filepath" | ||
) | ||
|
||
type Vendor struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
// InspectLibraries return the list with vendors | ||
func InspectLibraries(filepath string) ([]*gore.Package, error) { | ||
f, err := gore.Open(filepath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer func(f *gore.GoFile) { | ||
err := f.Close() | ||
if err != nil { | ||
|
||
} | ||
}(f) | ||
|
||
std2, err := f.GetVendors() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return std2, nil | ||
} | ||
|
||
func ConvertToJSONWithPosixPaths(path string) ([]byte, error) { | ||
vendors, err := InspectLibraries(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Convert the data to use POSIX paths | ||
for i := range vendors { | ||
vendors[i].Name = filepath.ToSlash(vendors[i].Name) | ||
} | ||
|
||
// Marshal the data to JSON | ||
dataJSON, err := json.Marshal(vendors) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return dataJSON, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
goInspector "github.com/nexB/go-inspector" | ||
"os" | ||
) | ||
|
||
func main() { | ||
args := os.Args | ||
if len(args) != 2 { | ||
fmt.Printf("Usage: %v \n", args[0]) | ||
fmt.Printf(" Load executable file file, and\n") | ||
fmt.Printf(" print portions of its creation info data.\n") | ||
return | ||
} | ||
jsonData, err := goInspector.ConvertToJSONWithPosixPaths(args[1]) | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(string(jsonData)) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/goretk/gore v0.11.1 h1:QEn9bI0ty//Dtk1sa2yYtssGzZHJIeROehiJEm953DQ= | ||
github.com/goretk/gore v0.11.1/go.mod h1:wZt6TJIR3gZJplzAApeIXA1BjQGd3PKbc2XincS3TAc= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= | ||
golang.org/x/arch v0.0.0-20220412001346-fc48f9fe4c15 h1:GVfVkciLYxn5mY5EncwAe0SXUn9Rm81rRkZ0TTmn/cU= | ||
golang.org/x/arch v0.0.0-20220412001346-fc48f9fe4c15/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= | ||
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= | ||
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= | ||
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99 h1:dbuHpmKjkDzSOMKAWl10QNlgaZUd3V1q99xc81tt2Kc= |