aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/feed.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-01 02:07:48 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-01 02:07:48 -0500
commit4ab54153c1448b6df9701efcd4b86e63e71c0760 (patch)
treefbbb6405782ceb88415eb17a217ce44ca9cf45fd /internal/feed/feed.go
parent58d86c1dcbc27772bf9eb91817091e6b430b90e8 (diff)
downloadcvez-4ab54153c1448b6df9701efcd4b86e63e71c0760.tar.bz2
cvez-4ab54153c1448b6df9701efcd4b86e63e71c0760.zip
add internal/feed/time*go
Diffstat (limited to 'internal/feed/feed.go')
-rw-r--r--internal/feed/feed.go39
1 files changed, 3 insertions, 36 deletions
diff --git a/internal/feed/feed.go b/internal/feed/feed.go
index c013877..cf0fd2d 100644
--- a/internal/feed/feed.go
+++ b/internal/feed/feed.go
@@ -4,8 +4,6 @@ import (
"encoding/json"
"fmt"
// "strconv"
- "regexp"
- "time"
)
const (
@@ -40,37 +38,6 @@ const (
// TODO: parse cpe
-// partial timestamp
-type PartialTime time.Time
-
-var partialTimeRe = regexp.MustCompile("\\A\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}Z\\z")
-
-// Unmarshal partial timestamp from JSON.
-func (me *PartialTime) UnmarshalJSON(b []byte) error {
- // decode string, check for error
- var s string
- if err := json.Unmarshal(b, &s); err != nil {
- return err
- }
-
- // match partial string regex
- if !partialTimeRe.MatchString(s) {
- return fmt.Errorf("invalid partial time string: %s", s)
- }
-
- // correct string suffix
- s = s[0:16] + ":00Z"
-
- // unmarshal time
- var t time.Time
- if err := t.UnmarshalText([]byte(s)); err != nil {
- return err
- }
-
- // return success
- return nil
-}
-
// Configuration node boolean operator.
type NodeOp int
@@ -666,10 +633,10 @@ type Item struct {
Impact Impact `json:"impact"`
// item published date
- PublishedDate PartialTime `json:"publishedDate"`
+ PublishedDate Time `json:"publishedDate"`
// last modification date
- LastModifiedDate PartialTime `json:"lastModifiedDate"`
+ LastModifiedDate Time `json:"lastModifiedDate"`
}
// NVD feed
@@ -687,7 +654,7 @@ type Feed struct {
NumCVEs uint64 `json:"CVE_data_numberOfCVEs,string"`
// data timestamp
- Timestamp PartialTime `json:"CVE_data_timestamp"`
+ Timestamp Time `json:"CVE_data_timestamp"`
// CVE items
Items []Item `json:"CVE_Items"`