Use json for gmtest session
This commit is contained in:
parent
b1e2634f33
commit
7675bea955
1 changed files with 6 additions and 6 deletions
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/gob"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
@ -45,13 +45,13 @@ func main() {
|
||||||
w.Out = os.Stdout
|
w.Out = os.Stdout
|
||||||
w.TimeFormat = time.Stamp
|
w.TimeFormat = time.Stamp
|
||||||
})).With().Timestamp().Logger()
|
})).With().Timestamp().Logger()
|
||||||
file, err := os.Open("session.gob")
|
file, err := os.Open("session.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
must(gob.NewDecoder(file).Decode(&sess))
|
must(json.NewDecoder(file).Decode(&sess))
|
||||||
log.Info().Msg("Loaded session?")
|
log.Info().Msg("Loaded session?")
|
||||||
}
|
}
|
||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
|
@ -101,15 +101,15 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveSession() {
|
func saveSession() {
|
||||||
file := mustReturn(os.OpenFile("session.gob", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600))
|
file := mustReturn(os.OpenFile("session.json", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600))
|
||||||
must(gob.NewEncoder(file).Encode(sess))
|
must(json.NewEncoder(file).Encode(sess))
|
||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func evtHandler(rawEvt any) {
|
func evtHandler(rawEvt any) {
|
||||||
switch evt := rawEvt.(type) {
|
switch evt := rawEvt.(type) {
|
||||||
case *events.ClientReady:
|
case *events.ClientReady:
|
||||||
log.Debug().Any("simData", evt.Session.Settings).Msg("Client is ready!")
|
log.Debug().Any("data", evt).Msg("Client is ready!")
|
||||||
case *events.PairSuccessful:
|
case *events.PairSuccessful:
|
||||||
log.Debug().Any("data", evt).Msg("Pair successful")
|
log.Debug().Any("data", evt).Msg("Pair successful")
|
||||||
sess.DevicePair = &libgm.DevicePair{
|
sess.DevicePair = &libgm.DevicePair{
|
||||||
|
|
Loading…
Reference in a new issue