parameters.go 714 B

1234567891011121314151617181920212223242526272829303132
  1. package govaluate
  2. import (
  3. "errors"
  4. )
  5. /*
  6. Parameters is a collection of named parameters that can be used by an EvaluableExpression to retrieve parameters
  7. when an expression tries to use them.
  8. */
  9. type Parameters interface {
  10. /*
  11. Get gets the parameter of the given name, or an error if the parameter is unavailable.
  12. Failure to find the given parameter should be indicated by returning an error.
  13. */
  14. Get(name string) (interface{}, error)
  15. }
  16. type MapParameters map[string]interface{}
  17. func (p MapParameters) Get(name string) (interface{}, error) {
  18. value, found := p[name]
  19. if !found {
  20. errorMessage := "No parameter '" + name + "' found."
  21. return nil, errors.New(errorMessage)
  22. }
  23. return value, nil
  24. }