forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprecation.go
36 lines (30 loc) · 902 Bytes
/
deprecation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package checker
import (
"encoding/json"
"errors"
"time"
"cloud.google.com/go/civil"
"github.com/tufin/oasdiff/diff"
)
const (
BetaDeprecationDays = 31
StableDeprecationDays = 180
)
func getSunsetDate(Extensions map[string]interface{}) (string, civil.Date, error) {
sunset, ok := Extensions[diff.SunsetExtension].(string)
if !ok {
sunsetJson, ok := Extensions[diff.SunsetExtension].(json.RawMessage)
if !ok {
return "", civil.Date{}, errors.New("sunset extension not found")
}
if err := json.Unmarshal(sunsetJson, &sunset); err != nil {
return "", civil.Date{}, errors.New("unmarshal failed")
}
}
if date, err := civil.ParseDate(sunset); err == nil {
return sunset, date, nil
} else if date, err := time.Parse(time.RFC3339, sunset); err == nil {
return sunset, civil.DateOf(date), nil
}
return sunset, civil.Date{}, errors.New("failed to parse sunset date")
}