Skip to content

Instantly share code, notes, and snippets.

@autarch
Created November 1, 2022 20:40
Show Gist options
  • Save autarch/24ff9eae44a33512c39c82696424a35e to your computer and use it in GitHub Desktop.
Save autarch/24ff9eae44a33512c39c82696424a35e to your computer and use it in GitHub Desktop.
// BuildInfo represents a response for the buildInfo command.
type BuildInfo struct {
Version string
VersionArray []int `bson:"versionArray"` // On MongoDB 2.0+; assembled from Version otherwise
GitVersion string `bson:"gitVersion"`
OpenSSLVersion string `bson:"OpenSSLVersion"`
SysInfo string `bson:"sysInfo"` // Deprecated and empty on MongoDB 3.2+.
Bits int
Debug bool
MaxObjectSize int `bson:"maxBsonObjectSize"`
}
// VersionAtLeast returns whether the BuildInfo version is greater than or
// equal to the provided version number. If more than one number is
// provided, numbers will be considered as major, minor, and so on.
func (bi *BuildInfo) VersionAtLeast(version ...int) bool {
for i, vi := range version {
if i == len(bi.VersionArray) {
return false
}
if bivi := bi.VersionArray[i]; bivi != vi {
return bivi >= vi
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment