version.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Unless explicitly stated otherwise all files in this repository are licensed
  2. // under the Apache License Version 2.0.
  3. // This product includes software developed at Datadog (https://www.datadoghq.com/).
  4. // Copyright 2016 Datadog, Inc.
  5. package version
  6. import (
  7. "regexp"
  8. "strconv"
  9. )
  10. // Tag specifies the current release tag. It needs to be manually
  11. // updated. A test checks that the value of Tag never points to a
  12. // git tag that is older than HEAD.
  13. const Tag = "v1.47.0"
  14. // Dissected version number. Filled during init()
  15. var (
  16. // Major is the current major version number
  17. Major int
  18. // Minor is the current minor version number
  19. Minor int
  20. // Patch is the current patch version number
  21. Patch int
  22. // RC is the current release candidate version number
  23. RC int
  24. )
  25. func init() {
  26. // This regexp matches the version format we use and captures major/minor/patch/rc in different groups
  27. r := regexp.MustCompile(`v(?P<ma>\d+)\.(?P<mi>\d+)\.(?P<pa>\d+)(-rc\.(?P<rc>\d+))?`)
  28. names := r.SubexpNames()
  29. captures := map[string]string{}
  30. // Associate each capture group match with the capture group's name to easily retrieve major/minor/patch/rc
  31. for k, v := range r.FindAllStringSubmatch(Tag, -1)[0] {
  32. captures[names[k]] = v
  33. }
  34. Major, _ = strconv.Atoi(captures["ma"])
  35. Minor, _ = strconv.Atoi(captures["mi"])
  36. Patch, _ = strconv.Atoi(captures["pa"])
  37. RC, _ = strconv.Atoi(captures["rc"])
  38. }