From 9d0ab0b818e810aeda19eb918d5a0fb54e995693 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 12 Oct 2023 21:49:42 -0400 Subject: [PATCH] fix token sync --- client.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index b7d9444..29b90ee 100644 --- a/client.go +++ b/client.go @@ -1,7 +1,7 @@ package matrixbotlib import ( - "io" + "log" "os" "strings" @@ -49,19 +49,25 @@ func NewMatrixClient(config *MatrixClientConfig, store mautrix.Storer) (*mautrix } func SyncToken(config *MatrixClientConfig) error { + log.Println("syncing token") + + t := make(map[string]interface{}) + data, err := os.ReadFile(config.filename) + if err != nil { + return err + } + err = yaml.Unmarshal([]byte(data), &t) + if err != nil { + return err + } + log.Println(t) + t["token"] = config.Token file, err := os.OpenFile(config.filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil { return err } defer file.Close() - t := make(map[string]interface{}) - data, err := io.ReadAll(file) - if err != nil { - return err - } - yaml.Unmarshal([]byte(data), &t) - t["token"] = config.Token enc := yaml.NewEncoder(file) err = enc.Encode(t)