Пример #1
0
func updateAppInfoToLocal(appInfo *AppInfo) error {
	var jsonObj *simplejson.Json
	infoPath := filepath.Join(utils.HomeDir(), ".leancloud", "app_keys")
	content, err := ioutil.ReadFile(infoPath)
	if err != nil {
		if !os.IsNotExist(err) {
			return err
		}
		jsonObj = simplejson.New()
	} else {
		jsonObj, err = simplejson.NewJson([]byte(content))
		if err != nil {
			return err
		}
	}
	jsonObj.Set(appInfo.AppID, map[string]string{
		"appKey":    appInfo.AppKey,
		"masterKey": appInfo.MasterKey,
	})
	body, err := jsonObj.EncodePretty()
	if err != nil {
		return err
	}
	return ioutil.WriteFile(infoPath, body, 0600)
}
Пример #2
0
func getAppInfoFromLocal(appID string) (*AppInfo, error) {
	infoPath := filepath.Join(utils.HomeDir(), ".leancloud", "app_keys")
	content, err := ioutil.ReadFile(infoPath)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, ErrAppInfoNotFound
		}
		return nil, err
	}

	jsonObj, err := simplejson.NewJson(content)
	if err != nil {
		return nil, err
	}

	_, err = jsonObj.Get(appID).Map()
	if err != nil {
		return nil, ErrAppInfoNotFound
	}

	return &AppInfo{
		AppID:     appID,
		AppKey:    jsonObj.Get(appID).Get("appKey").MustString(),
		MasterKey: jsonObj.Get(appID).Get("masterKey").MustString(),
	}, nil
}
Пример #3
0
func getCookies() ([]*http.Cookie, error) {
	content, err := ioutil.ReadFile(filepath.Join(utils.HomeDir(), ".leancloud", "cookies"))
	if err != nil {
		return nil, err
	}
	cookies := cookieparser.Parse(string(content))
	return cookies, nil
}
Пример #4
0
// saveCookies saves the cookies to `${HOME}/.leancloud/cookies`
func saveCookies(cookies []*http.Cookie) error {
	os.Mkdir(filepath.Join(utils.HomeDir(), ".leancloud"), 0700)

	content := []byte(cookieparser.ToString(cookies))
	return ioutil.WriteFile(filepath.Join(utils.HomeDir(), ".leancloud", "cookies"), content, 0600)
}