• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

spdx / tools-golang / 5008105195

17 May 2023 09:34PM UTC coverage: 94.782% (-0.04%) from 94.822%
5008105195

Pull #215

github

Brandon Lum
change packageVerification code for 2.1,2.2 to omitempty
Pull Request #215: Fixing some optional params: copyrightText, licenseListVersion, packageVerificationCode

7157 of 7551 relevant lines covered (94.78%)

15.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/spdx/v2/common/annotation.go
1
// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
2

3
package common
4

5
import (
6
        "encoding/json"
7
        "fmt"
8
        "strings"
9
)
10

11
type Annotator struct {
12
        Annotator string
13
        // including AnnotatorType: one of "Person", "Organization" or "Tool"
14
        AnnotatorType string
15
}
16

17
// UnmarshalJSON takes an annotator in the typical one-line format and parses it into an Annotator struct.
18
// This function is also used when unmarshalling YAML
19
func (a *Annotator) UnmarshalJSON(data []byte) error {
×
20
        // annotator will simply be a string
×
21
        annotatorStr := string(data)
×
22
        annotatorStr = strings.Trim(annotatorStr, "\"")
×
23

×
24
        annotatorFields := strings.SplitN(annotatorStr, ": ", 2)
×
25

×
26
        if len(annotatorFields) != 2 {
×
27
                return fmt.Errorf("failed to parse Annotator '%s'", annotatorStr)
×
28
        }
×
29

30
        a.AnnotatorType = annotatorFields[0]
×
31
        a.Annotator = annotatorFields[1]
×
32

×
33
        return nil
×
34
}
35

36
// MarshalJSON converts the receiver into a slice of bytes representing an Annotator in string form.
37
// This function is also used when marshalling to YAML
38
func (a Annotator) MarshalJSON() ([]byte, error) {
×
39
        if a.Annotator != "" {
×
40
                return json.Marshal(fmt.Sprintf("%s: %s", a.AnnotatorType, a.Annotator))
×
41
        }
×
42

43
        return []byte{}, nil
×
44
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc