type wildcardType … const noneWildcard … const majorWildcard … const minorWildcard … const patchWildcard … func wildcardTypefromInt(i int) wildcardType { … } type comparator … var compEQ … var compNE … var compGT … var compGE … var compLT … var compLE … type versionRange … // rangeFunc creates a Range from the given versionRange. func (vr *versionRange) rangeFunc() Range { … } type Range … // OR combines the existing Range with another Range using logical OR. func (rf Range) OR(f Range) Range { … } // AND combines the existing Range with another Range using logical AND. func (rf Range) AND(f Range) Range { … } // ParseRange parses a range and returns a Range. // If the range could not be parsed an error is returned. // // Valid ranges are: // - "<1.0.0" // - "<=1.0.0" // - ">1.0.0" // - ">=1.0.0" // - "1.0.0", "=1.0.0", "==1.0.0" // - "!1.0.0", "!=1.0.0" // // A Range can consist of multiple ranges separated by space: // Ranges can be linked by logical AND: // - ">1.0.0 <2.0.0" would match between both ranges, so "1.1.1" and "1.8.7" but not "1.0.0" or "2.0.0" // - ">1.0.0 <3.0.0 !2.0.3-beta.2" would match every version between 1.0.0 and 3.0.0 except 2.0.3-beta.2 // // Ranges can also be linked by logical OR: // - "<2.0.0 || >=3.0.0" would match "1.x.x" and "3.x.x" but not "2.x.x" // // AND has a higher precedence than OR. It's not possible to use brackets. // // Ranges can be combined by both AND and OR // // - `>1.0.0 <2.0.0 || >3.0.0 !4.2.1` would match `1.2.3`, `1.9.9`, `3.1.1`, but not `4.2.1`, `2.1.1` func ParseRange(s string) (Range, error) { … } // splitORParts splits the already cleaned parts by '||'. // Checks for invalid positions of the operator and returns an // error if found. func splitORParts(parts []string) ([][]string, error) { … } // buildVersionRange takes a slice of 2: operator and version // and builds a versionRange, otherwise an error. func buildVersionRange(opStr, vStr string) (*versionRange, error) { … } // inArray checks if a byte is contained in an array of bytes func inArray(s byte, list []byte) bool { … } // splitAndTrim splits a range string by spaces and cleans whitespaces func splitAndTrim(s string) (result []string) { … } // splitComparatorVersion splits the comparator from the version. // Input must be free of leading or trailing spaces. func splitComparatorVersion(s string) (string, string, error) { … } // getWildcardType will return the type of wildcard that the // passed version contains func getWildcardType(vStr string) wildcardType { … } // createVersionFromWildcard will convert a wildcard version // into a regular version, replacing 'x's with '0's, handling // special cases like '1.x.x' and '1.x' func createVersionFromWildcard(vStr string) string { … } // incrementMajorVersion will increment the major version // of the passed version func incrementMajorVersion(vStr string) (string, error) { … } // incrementMajorVersion will increment the minor version // of the passed version func incrementMinorVersion(vStr string) (string, error) { … } // expandWildcardVersion will expand wildcards inside versions // following these rules: // // * when dealing with patch wildcards: // >= 1.2.x will become >= 1.2.0 // <= 1.2.x will become < 1.3.0 // > 1.2.x will become >= 1.3.0 // < 1.2.x will become < 1.2.0 // != 1.2.x will become < 1.2.0 >= 1.3.0 // // * when dealing with minor wildcards: // >= 1.x will become >= 1.0.0 // <= 1.x will become < 2.0.0 // > 1.x will become >= 2.0.0 // < 1.0 will become < 1.0.0 // != 1.x will become < 1.0.0 >= 2.0.0 // // * when dealing with wildcards without // version operator: // 1.2.x will become >= 1.2.0 < 1.3.0 // 1.x will become >= 1.0.0 < 2.0.0 func expandWildcardVersion(parts [][]string) ([][]string, error) { … } func parseComparator(s string) comparator { … } // MustParseRange is like ParseRange but panics if the range cannot be parsed. func MustParseRange(s string) Range { … }