1// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 2// Run project: go run exampleRDFLoader.go ../sample-docs/rdf/SPDXRdfExample-v2.2.spdx.rdf 3package main 4 5import ( 6 "fmt" 7 "os" 8 "strings" 9 10 "github.com/spdx/tools-golang/rdfloader" 11) 12 13func getFilePathFromUser() (string, error) { 14 if len(os.Args) == 1 { 15 // user hasn't specified the rdf file path 16 return "", fmt.Errorf("kindly provide path of the rdf file to be loaded as a spdx-document while running this file") 17 } 18 return os.Args[1], nil 19} 20 21func main() { 22 // example to use the rdfLoader. 23 filePath, ok := getFilePathFromUser() 24 if ok != nil { 25 fmt.Println(fmt.Errorf("%v", ok)) 26 os.Exit(1) 27 } 28 file, err := os.Open(filePath) 29 if err != nil { 30 fmt.Println(fmt.Errorf("error opening File: %s", err)) 31 os.Exit(1) 32 } 33 34 // loading the spdx-document 35 doc, err := rdfloader.Load2_2(file) 36 if err != nil { 37 fmt.Println(fmt.Errorf("error parsing given spdx document: %s", err)) 38 os.Exit(1) 39 } 40 41 // Printing some of the document Information 42 fmt.Println(strings.Repeat("=", 80)) 43 fmt.Println("Some Attributes of the Document:") 44 fmt.Printf("Document Name: %s\n", doc.DocumentName) 45 fmt.Printf("DataLicense: %s\n", doc.DataLicense) 46 fmt.Printf("Document Namespace: %s\n", doc.DocumentNamespace) 47 fmt.Printf("SPDX Version: %s\n", doc.SPDXVersion) 48 fmt.Println(strings.Repeat("=", 80)) 49} 50