Skip to content

Commit

Permalink
Add New() method to Rel (#9)
Browse files Browse the repository at this point in the history
Fixes #8
  • Loading branch information
thomas-fossati authored Feb 18, 2021
1 parent b3df583 commit 285540f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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

0 comments on commit 285540f

Please sign in to comment.