| 1 | package namespace |
| 2 | |
| 3 | /* |
| 4 | Provides a Namespace class. |
| 5 | USAGE: |
| 6 | >>> ns, _ := namespace.New("https://spdx.org/rdf/terms") |
| 7 | >>> ns.Get("d4e2952") |
| 8 | {https://spdx.org/rdf/terms#d4e2952} |
| 9 | >>> ns.Get("Tag") |
| 10 | {https://spdx.org/rdf/terms#Tag} |
| 11 | |
| 12 | // Alternative initializations of namespace without abstraction |
| 13 | >> ns, _ := namespace.Namespace{uri.URIRef{"https://spdx.org/rdf/terms"}} |
| 14 | */ |
| 15 | |
| 16 | import ( |
| 17 | "github.com/spdx/gordf/uri" |
| 18 | ) |
| 19 | |
| 20 | type Namespace struct { |
| 21 | base uri.URIRef |
| 22 | } |
| 23 | |
| 24 | // Provides an abstraction to create a Namespace directly from uri string. |
| 25 | func New(namespace string) (ns Namespace, err error) { |
| 26 | uriref, err := uri.NewURIRef(namespace) |
| 27 | if err != nil { |
| 28 | return |
| 29 | } |
| 30 | return Namespace{uriref}, nil |
| 31 | } |
| 32 | |
| 33 | // Appends a fragment string at the end of the namespace string. |
| 34 | func (ns *Namespace) Get(fragment string) uri.URIRef { |
| 35 | return ns.base.AddFragment(fragment) |
| 36 | } |