decred.org/dcrwallet/v3@v3.1.0/chain/semver.go (about)

     1  // Copyright (c) 2016 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package chain
     6  
     7  import "fmt"
     8  
     9  type semver struct {
    10  	Major uint32 `json:"major"`
    11  	Minor uint32 `json:"minor"`
    12  	Patch uint32 `json:"patch"`
    13  }
    14  
    15  func semverCompatible(required, actual semver) bool {
    16  	switch {
    17  	case required.Major != actual.Major:
    18  		return false
    19  	case required.Minor > actual.Minor:
    20  		return false
    21  	case required.Minor == actual.Minor && required.Patch > actual.Patch:
    22  		return false
    23  	default:
    24  		return true
    25  	}
    26  }
    27  
    28  func (s semver) String() string {
    29  	return fmt.Sprintf("%d.%d.%d", s.Major, s.Minor, s.Patch)
    30  }