Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples : add example of jsonloader and remove existing conversion e…
…xamples - bug fixes in json saver done as well - test covereage of jsonparser increased Signed-off-by: Ujjwal Agarwal <ujjwalcoding012@gmail.com>
- Loading branch information
Showing
9 changed files
with
117 additions
and
31 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,55 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later | ||
|
||
// Example for: *jsonparser2v2* | ||
|
||
// This example demonstrates loading an SPDX json from disk into memory, | ||
// and then logging out some attributes to the console . | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spdx/tools-golang/jsonloader" | ||
) | ||
|
||
func main() { | ||
|
||
// check that we've received the right number of arguments | ||
args := os.Args | ||
if len(args) != 3 { | ||
fmt.Printf("Usage: %v <spdx-file-in> <spdx-file-out>\n", args[0]) | ||
fmt.Printf(" Load SPDX 2.2 tag-value file <spdx-file-in>, and\n") | ||
fmt.Printf(" save it out to <spdx-file-out>.\n") | ||
return | ||
} | ||
|
||
// open the SPDX file | ||
fileIn := args[1] | ||
r, err := os.Open(fileIn) | ||
if err != nil { | ||
fmt.Printf("Error while opening %v for reading: %v", fileIn, err) | ||
return | ||
} | ||
defer r.Close() | ||
|
||
// try to load the SPDX file's contents as a json file, version 2.2 | ||
doc, err := jsonloader.Load2_2(r) | ||
if err != nil { | ||
fmt.Printf("Error while parsing %v: %v", args[1], err) | ||
return | ||
} | ||
|
||
// if we got here, the file is now loaded into memory. | ||
fmt.Printf("Successfully loaded %s\n", args[1]) | ||
|
||
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)) | ||
} |
File renamed without changes.
File renamed without changes.
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
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
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
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
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
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