aboutsummaryrefslogtreecommitdiff
path: root/examples/7-rdfloader/exampleRDFLoader.go
diff options
context:
space:
mode:
authorSteve Winslow <steve@swinslow.net>2020-11-14 12:54:20 -0500
committerGitHub <noreply@github.com>2020-11-14 12:54:20 -0500
commitd6d5d11335fd65c2a6811e8c4c40b61b71024f4c (patch)
tree1d8a58fac1aecf0e0b22167b7fa504cd8f4eba52 /examples/7-rdfloader/exampleRDFLoader.go
parent4ca6cd1fc37977db1969fcfdfa33dabbb2588010 (diff)
parent54a920e8cd5408f4860d6d6cb6bd9df6a3d7e697 (diff)
downloadspdx-tools-d6d5d11335fd65c2a6811e8c4c40b61b71024f4c.tar.gz
Merge pull request #46 from spdx/gordf
Add RDF parsing support
Diffstat (limited to 'examples/7-rdfloader/exampleRDFLoader.go')
-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))
+}