本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.0KB

  1. package version
  2. import (
  3. "strings"
  4. )
  5. type Constraint struct {
  6. operator string
  7. version string
  8. }
  9. // Return a new Constrain and sets operator and version to compare
  10. func NewConstrain(operator, version string) *Constraint {
  11. constraint := new(Constraint)
  12. constraint.SetOperator(operator)
  13. constraint.SetVersion(version)
  14. return constraint
  15. }
  16. // Sets operator to compare
  17. func (self *Constraint) SetOperator(operator string) {
  18. self.operator = operator
  19. }
  20. // Get operator to compare
  21. func (self *Constraint) GetOperator() string {
  22. return self.operator
  23. }
  24. // Sets version to compare
  25. func (self *Constraint) SetVersion(version string) {
  26. self.version = version
  27. }
  28. // Get version to compare
  29. func (self *Constraint) GetVersion() string {
  30. return self.version
  31. }
  32. // Match a given version againts the constraint
  33. func (self *Constraint) Match(version string) bool {
  34. return Compare(version, self.version, self.operator)
  35. }
  36. // Return a string representation
  37. func (self *Constraint) String() string {
  38. return strings.Trim(self.operator+" "+self.version, " ")
  39. }
上海开阖软件有限公司 沪ICP备12045867号-1