README.md
1SPDX-License-Identifier: CC-BY-4.0
2
3# tools-golang Examples
4
5The `examples/` directory contains examples for how to use the various
6tools-golang sub-packages. Sample commands below should be run from
7within the example's subdirectory.
8
9## 1-load/
10
11*tvloader*, *spdx*
12
13This example demonstrates loading an SPDX tag-value file from disk into memory,
14and printing some of its contents to standard output.
15#### Run project: *go run example_load.go ../sample-docs/tv/hello.spdx*
16
17## 2-load-save/
18
19*tvloader*, *tvsaver*
20
21This example demonstrates loading an SPDX tag-value file from disk into memory,
22and re-saving it to a different file on disk.
23#### Run project: *go run example_load_save.go ../sample-docs/tv/hello.spdx test.spdx*
24
25## 3-build/
26
27*builder*, *tvsaver*
28
29This example demonstrates building an 'empty' SPDX document in memory that
30corresponds to a given directory's contents, including all files with their
31hashes and the package's verification code, and saving the document to disk.
32#### Run project: *go run example_build.go project2 ../../testdata/project2 test.spdx*
33
34## 4-search/
35
36*idsearcher*, *tvsaver*
37
38This example demonstrates building an SPDX document for a directory's contents
39(implicitly using *builder*); searching through that directory for [SPDX
40short-form IDs](https://spdx.org/ids/); filling those IDs into the document's
41Package and File license fields; and saving the resulting document to disk.
42#### Run project: *go run example_search.go project2 ../../testdata/project2/folder test.spdx*
43
44## 5-report/
45
46*reporter*, *tvloader*
47
48This example demonstrates loading an SPDX tag-value file from disk into memory,
49generating a basic report listing counts of the concluded licenses for its
50files, and printing the report to standard output.
51#### Run project: *go run example_report.go ../sample-docs/tv/hello.spdx*
52
53## 6-licensediff
54
55*licensediff*, *tvloader*
56
57This example demonstrates loading two SPDX tag-value files from disk into
58memory, and generating a diff of the concluded licenses for Files in Packages
59with matching IDs in each document.
60
61This is generally only useful when run with two SPDX documents that describe
62licenses for subsequent versions of the same set of files, AND if they have
63the same identifier in both documents.
64#### Run project: *go run example_licensediff.go ../sample-docs/tv/hello.spdx ../sample-docs/tv/hello-modified.spdx*
65
66## 7-rdfloader
67
68*rdfloader*, *spdx*
69
70This example demonstrates loading an SPDX rdf file from disk into memory
71and then printing the corresponding spdx struct for the document.
72#### Run project: *go run exampleRDFLoader.go ../sample-docs/rdf/SPDXRdfExample-v2.2.spdx.rdf*
73
74## 8-jsontotv
75
76*json*, *tvsaver*
77
78This example demonstrates loading an SPDX json from disk into memory
79and then re-saving it to a different file on disk in tag-value format.
80#### Run project: *go run examplejsontotv.go ../sample-docs/json/SPDXJSONExample-v2.2.spdx.json example.spdx*
81
82## 9-tvtojson
83
84*json*, *tvloader*
85
86This example demonstrates loading an SPDX tag-value from disk into memory
87and then re-saving it to a different file on disk in json format.
88#### Run project: *go run exampletvtojson.go ../sample-docs/tv/hello.spdx example.json*
89
90## 10-jsonloader
91
92*json*
93
94This example demonstrates loading an SPDX json from disk into memory
95and then logging some of the attributes to the console.
96#### Run project: *go run example_json_loader.go ../sample-docs/json/SPDXJSONExample-v2.2.spdx.json*
97
98## 11-yamltotv
99
100*yaml* *tvsaver*
101
102This example demonstrates loading an SPDX yaml from disk into memory
103and then re-saving it to a different file on disk in tag-value format.
104#### Run project: *go run exampleyamltotv.go ../sample-docs/yaml/SPDXYAMLExample-2.2.spdx.yaml test.spdx*
105
106## 12-tvtoyaml
107
108*yaml* *tvloader*
109
110This example demonstrates loading an SPDX tag-value from disk into memory
111and then re-saving it to a different file on disk in yaml format.
112#### Run project: *go run exampletvtoyaml.go ../sample-docs/tv/hello.spdx example.yaml*
113
114## 13-yamlloader
115
116*yaml*
117
118This example demonstrates loading an SPDX yaml from disk into memory
119and then logging some of the attributes to the console.
120#### Run project: *go run exampleYAMLLoader.go ../sample-docs/yaml/SPDXYAMLExample-2.2.spdx.yaml*
121