~edwargix/axon

a41589f4d4b1a4efa9562384db63b8493cf742cd — David Florness 3 years ago 7c9daff
Properly create axalon data dir
1 files changed, 12 insertions(+), 3 deletions(-)

M shared/auth.go
M shared/auth.go => shared/auth.go +12 -3
@@ 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)
}