github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/config/remoteconfig/state.go (about) 1 package remoteconfig 2 3 import ( 4 "time" 5 6 statetypes "github.com/ddev/ddev/pkg/config/state/types" 7 "github.com/ddev/ddev/pkg/util" 8 ) 9 10 func newState(stateManager statetypes.State) *state { 11 state := &state{ 12 stateManager: stateManager, 13 } 14 15 if err := state.load(); err != nil { 16 util.Debug("Error while loading state: %s", err) 17 } 18 19 return state 20 } 21 22 type state struct { 23 stateManager statetypes.State 24 stateEntry 25 } 26 27 type stateEntry struct { 28 UpdatedAt time.Time `yaml:"updated_at"` 29 LastNotificationAt time.Time `yaml:"last_notification_at"` 30 LastTickerAt time.Time `yaml:"last_ticker_at"` 31 LastTickerMessage int `yaml:"last_ticker_message"` 32 } 33 34 const stateKey = "remote_config" 35 36 func (s *state) load() error { 37 return s.stateManager.Get(stateKey, &s.stateEntry) 38 } 39 40 func (s *state) save() (err error) { 41 err = s.stateManager.Set(stateKey, s.stateEntry) 42 if err != nil { 43 return 44 } 45 46 return s.stateManager.Save() 47 }