package main import ( "io/ioutil" "os" "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) { data, err := assertDatadir() if err != nil { return } path := filepath.Join(data, RelJidPath) _ = ioutil.WriteFile(path, []byte(j), 0644) } func getLastJid() string { data, err := assertDatadir() if err != nil { return "" } path := filepath.Join(data, RelJidPath) content, err := ioutil.ReadFile(path) if err != nil { return "" } 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 { return "", err } path := filepath.Join(home, RelDataPath) err = os.MkdirAll(path, 0755) if err != nil { return "", err } return path, nil }