Exemple #1
0
func changeQuota(w http.ResponseWriter, r *http.Request, t *auth.Token) error {
	owner := r.URL.Query().Get(":owner")
	q, err := strconv.Atoi(r.PostFormValue("quota"))
	if err != nil {
		return &errors.HTTP{Code: http.StatusInternalServerError, Message: "invalid parameter"}
	}
	err = quota.Set(owner, uint(q))
	if err != nil {
		return &errors.HTTP{Code: http.StatusNotFound, Message: err.Error()}
	}
	w.Write([]byte("Quota changed sucessfully."))
	return nil
}
Exemple #2
0
func ExampleSet() {
	err := quota.Create("*****@*****.**", 3)
	if err != nil {
		panic(err)
	}
	quota.Reserve("*****@*****.**", "me/0")
	quota.Reserve("*****@*****.**", "me/1")
	quota.Reserve("*****@*****.**", "me/2")
	quota.Set("*****@*****.**", 2)
	quota.Reserve("*****@*****.**", "me/3") // ErrQuotaExceeded
	quota.Release("*****@*****.**", "me/2")
	quota.Reserve("*****@*****.**", "me/3") // ErrQuotaExceeded
	quota.Release("*****@*****.**", "me/1")
	quota.Reserve("*****@*****.**", "me/3") // Everything is ok now
}