github.com/larrabee/ratelimit@v1.0.6-0.20191102113931-712217ec4fdc/errors.go (about)

     1  package ratelimit
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  type QuantumError struct {
     8  	Rate float64
     9  }
    10  
    11  func (e *QuantumError) Error() string {
    12  	return fmt.Sprintf("cannot find suitable quantum for rate: %f", e.Rate)
    13  }
    14  
    15  type Field int
    16  
    17  const (
    18  	FieldFillInterval = iota
    19  	FieldCapacity
    20  	FieldQuantum
    21  )
    22  
    23  var fieldMap = map[Field]string{FieldFillInterval: "Interval", FieldCapacity: "Capacity", FieldQuantum: "Quantum"}
    24  
    25  type ValueError struct {
    26  	Field Field
    27  	Value int64
    28  }
    29  
    30  func (e *ValueError) Error() string {
    31  	return fmt.Sprintf("Field '%s' have incorrect value: %d", fieldMap[e.Field], e.Value)
    32  }