diff options
author | Sadaf Ebrahimi <sadafebrahimi@google.com> | 2023-01-25 20:36:34 +0000 |
---|---|---|
committer | Sadaf Ebrahimi <sadafebrahimi@google.com> | 2023-01-25 20:37:29 +0000 |
commit | 75f88b4895c444b4dfa2566595a7bf2774cdd389 (patch) | |
tree | 6ea4841a079772cb06df5ec2cf99637f8d53805b /examples/7-rdfloader | |
parent | 5f73058e15df15ab2a35ca0c9d506b4fd0a83de7 (diff) | |
parent | 843bc985256a3a3ae317bc5b11b9fbdc8b6aadd7 (diff) | |
download | spdx-tools-75f88b4895c444b4dfa2566595a7bf2774cdd389.tar.gz |
Upgrade spdx-tools to v0.4.0platform-tools-34.0.0platform-tools-33.0.4
This project was upgraded with external_updater.
Usage: tools/external_updater/updater.sh update spdx-tools
For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
Test: TreeHugger
Change-Id: Ifd1b9282e8eea85b2ac1e3032e2f0a2c3ea1f1b4
Diffstat (limited to 'examples/7-rdfloader')
-rw-r--r-- | examples/7-rdfloader/exampleRDFLoader.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/7-rdfloader/exampleRDFLoader.go b/examples/7-rdfloader/exampleRDFLoader.go new file mode 100644 index 0000000..81206a4 --- /dev/null +++ b/examples/7-rdfloader/exampleRDFLoader.go @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +// Run project: go run exampleRDFLoader.go ../sample-docs/rdf/SPDXRdfExample-v2.2.spdx.rdf +package main + +import ( + "fmt" + "os" + "strings" + + "github.com/spdx/tools-golang/rdfloader" +) + +func getFilePathFromUser() (string, error) { + if len(os.Args) == 1 { + // user hasn't specified the rdf file path + return "", fmt.Errorf("kindly provide path of the rdf file to be loaded as a spdx-document while running this file") + } + return os.Args[1], nil +} + +func main() { + // example to use the rdfLoader. + filePath, ok := getFilePathFromUser() + if ok != nil { + fmt.Println(fmt.Errorf("%v", ok)) + os.Exit(1) + } + file, err := os.Open(filePath) + if err != nil { + fmt.Println(fmt.Errorf("error opening File: %s", err)) + os.Exit(1) + } + + // loading the spdx-document + doc, err := rdfloader.Load2_2(file) + if err != nil { + fmt.Println(fmt.Errorf("error parsing given spdx document: %s", err)) + os.Exit(1) + } + + // Printing some of the document Information + fmt.Println(strings.Repeat("=", 80)) + fmt.Println("Some Attributes of the Document:") + fmt.Printf("Document Name: %s\n", doc.DocumentName) + fmt.Printf("DataLicense: %s\n", doc.DataLicense) + fmt.Printf("Document Namespace: %s\n", doc.DocumentNamespace) + fmt.Printf("SPDX Version: %s\n", doc.SPDXVersion) + fmt.Println(strings.Repeat("=", 80)) +} |