github.com/cyverse/go-irodsclient@v0.13.2/irods/types/version.go (about)

     1  package types
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  )
     7  
     8  // IRODSVersion contains irods version information
     9  type IRODSVersion struct {
    10  	ReleaseVersion string // e.g., "rods4.2.8"
    11  	APIVersion     string
    12  	ReconnectPort  int
    13  	ReconnectAddr  string
    14  	Cookie         int
    15  }
    16  
    17  // GetReleaseVersion returns version parts (major, minor, patch)
    18  func (ver *IRODSVersion) GetReleaseVersion() (int, int, int) {
    19  	major := 0
    20  	minor := 0
    21  	patch := 0
    22  
    23  	releaseVersion := strings.ToLower(ver.ReleaseVersion)
    24  	releaseVersion = strings.TrimPrefix(releaseVersion, "rods")
    25  
    26  	vers := strings.Split(releaseVersion, ".")
    27  	if len(vers) >= 1 {
    28  		m, err := strconv.Atoi(vers[0])
    29  		if err == nil {
    30  			major = m
    31  		}
    32  	}
    33  
    34  	if len(vers) >= 2 {
    35  		m, err := strconv.Atoi(vers[1])
    36  		if err == nil {
    37  			minor = m
    38  		}
    39  	}
    40  
    41  	if len(vers) >= 3 {
    42  		p, err := strconv.Atoi(vers[2])
    43  		if err == nil {
    44  			patch = p
    45  		}
    46  	}
    47  
    48  	return major, minor, patch
    49  }
    50  
    51  // HasHigherVersionThan returns if given version is higher or equal than current version
    52  func (ver *IRODSVersion) HasHigherVersionThan(major int, minor int, patch int) bool {
    53  	smajor, sminor, spatch := ver.GetReleaseVersion()
    54  	if smajor > major {
    55  		return true
    56  	}
    57  	if smajor < major {
    58  		return false
    59  	}
    60  	// major is equal
    61  	if sminor > minor {
    62  		return true
    63  	}
    64  	if sminor < minor {
    65  		return false
    66  	}
    67  	// minor is equal
    68  	if spatch > patch {
    69  		return true
    70  	}
    71  	if spatch < patch {
    72  		return false
    73  	}
    74  	return true
    75  }