11package sdk
22
33import (
4+ json "encoding/json"
45 "time"
56)
67
@@ -18,6 +19,46 @@ type Environment struct {
1819 FromRepository string `json:"from_repository,omitempty"`
1920}
2021
22+ // UnmarshalJSON custom for last modified.
23+ func (e * Environment ) UnmarshalJSON (data []byte ) error {
24+ var tmp struct {
25+ ID int64 `json:"id"`
26+ Name string `json:"name"`
27+ Variables []Variable `json:"variables"`
28+ ProjectKey string `json:"project_key"`
29+ Created time.Time `json:"created"`
30+ Keys []EnvironmentKey `json:"keys"`
31+ Usage * Usage `json:"usage"`
32+ FromRepository string `json:"from_repository"`
33+ }
34+
35+ if err := json .Unmarshal (data , & tmp ); err != nil {
36+ return err
37+ }
38+ e .ID = tmp .ID
39+ e .Name = tmp .Name
40+ e .Variables = tmp .Variables
41+ e .ProjectKey = tmp .ProjectKey
42+ e .Created = tmp .Created
43+ e .Keys = tmp .Keys
44+ e .Usage = tmp .Usage
45+ e .FromRepository = tmp .FromRepository
46+
47+ var v map [string ]interface {}
48+ if err := json .Unmarshal (data , & v ); err != nil {
49+ return err
50+ }
51+ if lastModifiedNumber , ok := v ["last_modified" ].(float64 ); ok {
52+ e .LastModified = time .Unix (int64 (lastModifiedNumber ), 0 )
53+ }
54+ if lastModifiedString , ok := v ["last_modified" ].(string ); ok {
55+ date , _ := time .Parse (time .RFC3339 , lastModifiedString )
56+ e .LastModified = date
57+ }
58+
59+ return nil
60+ }
61+
2162// EnvironmentVariableAudit represents an audit on an environment variable
2263type EnvironmentVariableAudit struct {
2364 ID int64 `json:"id" yaml:"-" db:"id"`
0 commit comments