func (self *Service) PersistFile(automata *gofsm.Automata) { w, err := os.Create(config.ConfigPath("automata.state")) if err != nil { log.Fatalln("Persisting automata state failed:", err) } defer w.Close() enc := json.NewEncoder(w) enc.Encode(automata.Persist()) }
func (self *Service) RestoreFile(automata *gofsm.Automata) { r, err := os.Open(config.ConfigPath("automata.state")) if err != nil { log.Println("Restoring automata state failed:", err) return } dec := json.NewDecoder(r) var p gofsm.AutomataState err = dec.Decode(&p) if err != nil { log.Println("Restoring automata state failed:", err) return } automata.Restore(p) }