@@ 22,14 22,19 @@ type AuthInfo struct {
Username string `json:"username"`
}
-var authFname = xdg.DataHome() + "/axon/auth.json"
+var axonDir = xdg.DataHome() + "/axon"
+var authFname = axonDir + "/auth.json"
func GetAuthInfo() (authInfo *AuthInfo, err error) {
if _, err = os.Stat(authFname); os.IsNotExist(err) {
fmt.Println("no cached auth data found; inquiring for credentials")
authInfo, err = inquireForAuthInfo()
- if err == nil {
- authInfo.save()
+ if err != nil {
+ return nil, err
+ }
+ err = authInfo.save()
+ if err != nil {
+ return nil, err
}
return authInfo, err
}
@@ 126,5 131,9 @@ func (authInfo *AuthInfo) save() error {
if err != nil {
return err
}
+ err = os.MkdirAll(axonDir, 0700)
+ if err != nil {
+ return err
+ }
return ioutil.WriteFile(authFname, jsonBytes, 0600)
}