Use of vars instead of func

This commit is contained in:
Matthieu MOREL 2021-06-13 13:30:16 +02:00 committed by GitHub
parent c81cff094e
commit e72b1e5f25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 14 deletions

View file

@ -1,5 +1,7 @@
package cwe package cwe
import "fmt"
const ( const (
// Acronym is the acronym of CWE // Acronym is the acronym of CWE
Acronym = "CWE" Acronym = "CWE"
@ -14,6 +16,11 @@ const (
) )
var ( var (
// InformationURI link to the published CWE PDF
InformationURI = fmt.Sprintf("https://cwe.mitre.org/data/published/cwe_v%s.pdf/", Version)
// DownloadURI link to the zipped XML of the CWE list
DownloadURI = fmt.Sprintf("https://cwe.mitre.org/data/xml/cwec_v%s.xml.zip", Version)
data = map[string]*Weakness{} data = map[string]*Weakness{}
weaknesses = []*Weakness{ weaknesses = []*Weakness{

View file

@ -32,13 +32,3 @@ func (w *Weakness) MarshalJSON() ([]byte, error) {
URL: w.SprintURL(), URL: w.SprintURL(),
}) })
} }
// InformationURI link to the published CWE PDF
func InformationURI() string {
return fmt.Sprintf("https://cwe.mitre.org/data/published/cwe_v%s.pdf/", Version)
}
// DownloadURI link to the zipped XML of the CWE list
func DownloadURI() string {
return fmt.Sprintf("https://cwe.mitre.org/data/xml/cwec_v%s.xml.zip", Version)
}

View file

@ -11,8 +11,8 @@ var _ = Describe("CWE Types", func() {
}) })
Context("when consulting cwe types", func() { Context("when consulting cwe types", func() {
It("it should retrieves the information and download URIs", func() { It("it should retrieves the information and download URIs", func() {
Expect(cwe.InformationURI()).To(Equal("https://cwe.mitre.org/data/published/cwe_v4.4.pdf/")) Expect(cwe.InformationURI).To(Equal("https://cwe.mitre.org/data/published/cwe_v4.4.pdf/"))
Expect(cwe.DownloadURI()).To(Equal("https://cwe.mitre.org/data/xml/cwec_v4.4.xml.zip")) Expect(cwe.DownloadURI).To(Equal("https://cwe.mitre.org/data/xml/cwec_v4.4.xml.zip"))
}) })
It("it should retrieves the weakness ID and URL", func() { It("it should retrieves the weakness ID and URL", func() {

View file

@ -104,9 +104,9 @@ func buildSarifReportingDescriptorRelationship(weakness *cwe.Weakness) *Reportin
} }
func buildCWETaxonomy(taxa []*ReportingDescriptor) *ToolComponent { func buildCWETaxonomy(taxa []*ReportingDescriptor) *ToolComponent {
return NewToolComponent(cwe.Acronym, cwe.Version, cwe.InformationURI()). return NewToolComponent(cwe.Acronym, cwe.Version, cwe.InformationURI).
WithReleaseDateUtc(cwe.ReleaseDateUtc). WithReleaseDateUtc(cwe.ReleaseDateUtc).
WithDownloadURI(cwe.DownloadURI()). WithDownloadURI(cwe.DownloadURI).
WithOrganization(cwe.Organization). WithOrganization(cwe.Organization).
WithShortDescription(NewMultiformatMessageString(cwe.Description)). WithShortDescription(NewMultiformatMessageString(cwe.Description)).
WithIsComprehensive(true). WithIsComprehensive(true).