コード例 #1
0
ファイル: cli.go プロジェクト: vichetuc/boxed
func processUserDelta(email string) {
	articlesCursor, _ := datastore.GetCurrentCursor(email, "/published")
	at, err := datastore.LoadUserToken(email)
	if err != nil {
		log.Fatal(err)
		return
	}
	dbc := dropbox.NewClient(at, config.AppToken)

	//process articles
	d, _ := dbc.GetDelta("/published", articlesCursor)

	for _, v := range d.Deleted {
		a, err := datastore.LoadArticle(email + ":article:" + v)
		if err == nil {
			a.Delete()
			log.Printf("deleted: %s", v)
		}
	}

	wait.Wait(len(d.Updated), func(index int) {
		entry, _ := dbc.GetMetadata(d.Updated[index], true)
		file, _ := dbc.GetFile(d.Updated[index])
		content, _ := ioutil.ReadAll(file)
		article := datastore.ParseEntry(*entry, content)
		article.GenerateID(email)
		article.Save()
		log.Printf("updated: %s", article.Path)
	})

	datastore.ArticlesReindex(email)
	datastore.SaveCurrentCursor(email, "/published", d.Cursor)

	//process images
	imageCursor, _ := datastore.GetCurrentCursor(email, "/images")
	d, err = dbc.GetDelta("/images", imageCursor)
	for _, v := range d.Deleted {
		err := os.Remove("./public" + v)
		if err != nil {
			log.Println(err)
		}
		log.Printf("deleted: %s", v)
	}

	wait.Wait(len(d.Updated), func(index int) {
		file, _ := dbc.GetFile(d.Updated[index])
		content, _ := ioutil.ReadAll(file)
		imgPath, _ := filepath.Abs("./public" + d.Updated[index])
		os.MkdirAll(filepath.Dir(imgPath), 0755)
		err = ioutil.WriteFile("./public"+d.Updated[index], content, 0644)
		if err != nil {
			log.Println(err)
		}
		log.Printf("updated: %s", d.Updated[index])
	})
	datastore.SaveCurrentCursor(email, "/images", d.Cursor)

}
コード例 #2
0
ファイル: validations.go プロジェクト: ryanzec/going
// Validate takes in n number of Validator objects and will run
// them and return back a point to a Errors object that
// will contain any errors.
func Validate(validators ...Validator) *Errors {
	errors := NewErrors()

	wait.Wait(len(validators), func(index int) {
		validator := validators[index]
		validator.IsValid(errors)
	})

	return errors
}
コード例 #3
0
ファイル: client.go プロジェクト: li-ang/enterprise-client
// Save does all of the heavy lifting of saving a Saveable
// Type to the Enterpise API. This will take care of things
// like building the full path, setting the `token` on the
// request if one is available, etc... It will also check
// the status code of the response and handle non-successful
// responses by generating a proper `error` for them.
func (c *Client) Save(s Saveable) (*Response, error) {
	r := NewResponse()
	wait.Wait(len(c.Hosts), func(i int) {
		h := c.Hosts[i]
		res, err := h.save(s)
		if err != nil {
			r.AddError(h, err)
		}
		r.AddResponse(h, res)
	})

	return r, r.Error
}
コード例 #4
0
ファイル: client.go プロジェクト: li-ang/enterprise-client
func (c *Client) Register(p *Product) (*Response, error) {
	r := NewResponse()
	wait.Wait(len(c.Hosts), func(i int) {
		h := c.Hosts[i]
		res, err := h.save(p)
		if err != nil {
			r.AddError(h, err)
			return
		}
		if h.Primary {
			h.Token = p.Token
			h.SecretKey = p.Secret
		}
		r.AddResponse(h, res)
	})

	return r, r.Error
}