packageversionimport("strings")typeConstraintstruct{operatorstringversionstring}// Return a new Constrain and sets operator and version to comparefuncNewConstrain(operator,versionstring)*Constraint{constraint:=new(Constraint)constraint.SetOperator(operator)constraint.SetVersion(version)returnconstraint}// Sets operator to comparefunc(self*Constraint)SetOperator(operatorstring){self.operator=operator}// Get operator to comparefunc(self*Constraint)GetOperator()string{returnself.operator}// Sets version to comparefunc(self*Constraint)SetVersion(versionstring){self.version=version}// Get version to comparefunc(self*Constraint)GetVersion()string{returnself.version}// Match a given version againts the constraintfunc(self*Constraint)Match(versionstring)bool{returnCompare(version,self.version,self.operator)}// Return a string representationfunc(self*Constraint)String()string{returnstrings.Trim(self.operator+" "+self.version," ")}