aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRishabhBhatnagar <bhatnagarrishabh4@gmail.com>2020-08-19 20:41:36 +0530
committerRishabhBhatnagar <bhatnagarrishabh4@gmail.com>2020-08-19 20:41:36 +0530
commitf6091982769ca08e7604a1be79afdb8902717114 (patch)
tree340fe0eb69015ce81db51f0c839782585b74f7f9 /examples
parent5a270f97f4106cf989761f9143e23132c1bffb3c (diff)
downloadspdx-tools-f6091982769ca08e7604a1be79afdb8902717114.tar.gz
Add Support For RDFLoader Without License
- The Licensing Info is Incomplete - Some other attributes are not set in the tools-golang data model. Signed-off-by: RishabhBhatnagar <bhatnagarrishabh4@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/7-rdfloader/exampleRDFLoader.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/7-rdfloader/exampleRDFLoader.go b/examples/7-rdfloader/exampleRDFLoader.go
new file mode 100644
index 0000000..2e44935
--- /dev/null
+++ b/examples/7-rdfloader/exampleRDFLoader.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ "fmt"
+ "github.com/spdx/tools-golang/rdfloader"
+ "os"
+ "strings"
+)
+
+func getFilePathFromUser() string {
+ if len(os.Args) == 1 {
+ // user hasn't specified the rdf file path
+ panic("kindly provide path of the rdf file to be loaded as a spdx-document while running this file")
+ }
+ return os.Args[1]
+}
+
+func main() {
+ // example to use the rdfLoader.
+ filePath := getFilePathFromUser()
+ file, err := os.Open(filePath)
+ if err != nil {
+ panic(fmt.Errorf("error opening File: %s", err))
+ }
+
+ // 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.CreationInfo.DocumentName)
+ fmt.Printf("DataLicense: %s\n", doc.CreationInfo.DataLicense)
+ fmt.Printf("Document NameSpace: %s\n", doc.CreationInfo.DocumentNamespace)
+ fmt.Printf("SPDX Document Version: %s\n", doc.CreationInfo.SPDXVersion)
+ fmt.Println(strings.Repeat("=", 80))
+}