diff options
Diffstat (limited to 'persistence.go')
-rw-r--r-- | persistence.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/persistence.go b/persistence.go index 5199fc5..bc6eee4 100644 --- a/persistence.go +++ b/persistence.go @@ -6,9 +6,16 @@ import ( "path/filepath" ) +type persistentString uint8 + +const ( + Jid persistentString = iota +) + const ( RelDataPath = `/.config/limox` RelJidPath = `/last_jid.txt` + RelPwdPath = `/last_pwd.txt` ) func setLastJid(j string) { @@ -38,6 +45,33 @@ func getLastJid() string { return string(content) } +func setLastPwd(p string) { + data, err := assertDatadir() + if err != nil { + return + } + + path := filepath.Join(data, RelPwdPath) + + _ = ioutil.WriteFile(path, []byte(p), 0600) +} + +func getLastPwd() string { + data, err := assertDatadir() + if err != nil { + return "" + } + + path := filepath.Join(data, RelPwdPath) + + content, err := ioutil.ReadFile(path) + if err != nil { + return "" + } + + return string(content) +} + func assertDatadir() (string, error) { home, err := os.UserHomeDir() if err != nil { |