[Golang] Code snippets - Semver comparison

To make the project backward-compatible, a common util function for comparing the semantic version is indispensable. Here is a Golang solution implemented by leveraging go-semver package. package utils import "github.com/coreos/go-semver/semver" // CompareSemanticVersion compares two string written in semver format // return 0 indicates that the first version equals to the second version // return 1 indicates that the first version is greater than the second version // return -1 indicates that the first version is less than the second version func CompareSemanticVersion(current, last string) int { if current == last { return 0 } currentVersion := semver.New(current) lastVersion := semver.New(last) if currentVersion.LessThan(*lastVersion) { return -1 } return 1 } The unit test: ...

[Helm] How to check semantic version in helm chart

Helm chart supports the semantic veresion check function. We can find it here 1. Compare semantic version string It is very helpful for some cases. For example, if the helm chart needs to decide the probe port based on the docker image version. Let’s say that a web service started to support HTTPs feature since version 22.5.0, so if the installed docker image is after 22.5.0, the default probe port should be 8443. Otherwise, the default probe port will be 8000 ...

DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !