Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add New() method to Rel #9

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ func Example_useAPIToBuildPSAEndorsementSoftwareBundle() {
_ = tag.AddEntity(*entity)

// make links and append them to tag
link, _ := NewLink("example.acme.roadrunner-hw-v1-0-0", Rel{"psa-rot-compound"})
link, _ := NewLink("example.acme.roadrunner-hw-v1-0-0", *NewRel("psa-rot-compound"))
_ = tag.AddLink(*link)

link, _ = NewLink("example.acme.roadrunner-sw-bl-v1-0-0", Rel{RelComponent})
link, _ = NewLink("example.acme.roadrunner-sw-bl-v1-0-0", *NewRel(RelComponent))
_ = tag.AddLink(*link)

link, _ = NewLink("example.acme.roadrunner-sw-prot-v1-0-0", Rel{RelComponent})
link, _ = NewLink("example.acme.roadrunner-sw-prot-v1-0-0", *NewRel(RelComponent))
_ = tag.AddLink(*link)

link, _ = NewLink("example.acme.roadrunner-sw-arot-v1-0-0", Rel{RelComponent})
link, _ = NewLink("example.acme.roadrunner-sw-arot-v1-0-0", *NewRel(RelComponent))
_ = tag.AddLink(*link)

// encode tag to JSON
Expand Down Expand Up @@ -71,7 +71,7 @@ func Example_useAPIToBuildPSAEndorsementSoftwareComponent() {
_ = tag.AddPayload(*payload)

// make link to the HW RoT
link, _ := NewLink("example.acme.roadrunner-hw-v1-0-0", Rel{"psa-rot-compound"})
link, _ := NewLink("example.acme.roadrunner-hw-v1-0-0", *NewRel("psa-rot-compound"))
_ = tag.AddLink(*link)

// encode tag to JSON
Expand Down Expand Up @@ -102,7 +102,7 @@ func Example_completePrimaryTag() {
_ = entity.SetRegID("mycoyote.com")
_ = tag.AddEntity(*entity)

link, _ := NewLink("www.gnu.org/licenses/gpl.txt", Rel{"license"})
link, _ := NewLink("www.gnu.org/licenses/gpl.txt", *NewRel("license"))
_ = tag.AddLink(*link)

meta := SoftwareMeta{
Expand Down
8 changes: 8 additions & 0 deletions rel.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ var (
}
)

// NewRel returns a Rel initialized with the supplied value v
func NewRel(v interface{}) *Rel {
if isStringOrCode(v, "rel") != nil {
return nil
}
return &Rel{v}
}

// String returns the value of the Rel receiver as a string
func (r Rel) String() string {
return codeStringer(r.val, relToString, "rel")
Expand Down