version.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2019-2022 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. package version
  15. import "strings"
  16. const version = "2.3.3-dev"
  17. var (
  18. commit = ""
  19. date = ""
  20. info Info
  21. )
  22. // Info defines version details
  23. type Info struct {
  24. Version string `json:"version"`
  25. BuildDate string `json:"build_date"`
  26. CommitHash string `json:"commit_hash"`
  27. Features []string `json:"features"`
  28. }
  29. // GetAsString returns the string representation of the version
  30. func GetAsString() string {
  31. var sb strings.Builder
  32. sb.WriteString(info.Version)
  33. if info.CommitHash != "" {
  34. sb.WriteString("-")
  35. sb.WriteString(info.CommitHash)
  36. }
  37. if info.BuildDate != "" {
  38. sb.WriteString("-")
  39. sb.WriteString(info.BuildDate)
  40. }
  41. if len(info.Features) > 0 {
  42. sb.WriteString(" ")
  43. sb.WriteString(strings.Join(info.Features, " "))
  44. }
  45. return sb.String()
  46. }
  47. func init() {
  48. info = Info{
  49. Version: version,
  50. CommitHash: commit,
  51. BuildDate: date,
  52. }
  53. }
  54. // AddFeature adds a feature description
  55. func AddFeature(feature string) {
  56. info.Features = append(info.Features, feature)
  57. }
  58. // Get returns the Info struct
  59. func Get() Info {
  60. return info
  61. }