version.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2019-2023 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 defines SFTPGo version details
  15. package version
  16. import "strings"
  17. const version = "2.5.0"
  18. var (
  19. commit = ""
  20. date = ""
  21. info Info
  22. )
  23. // Info defines version details
  24. type Info struct {
  25. Version string `json:"version"`
  26. BuildDate string `json:"build_date"`
  27. CommitHash string `json:"commit_hash"`
  28. Features []string `json:"features"`
  29. }
  30. // GetAsString returns the string representation of the version
  31. func GetAsString() string {
  32. var sb strings.Builder
  33. sb.WriteString(info.Version)
  34. if info.CommitHash != "" {
  35. sb.WriteString("-")
  36. sb.WriteString(info.CommitHash)
  37. }
  38. if info.BuildDate != "" {
  39. sb.WriteString("-")
  40. sb.WriteString(info.BuildDate)
  41. }
  42. if len(info.Features) > 0 {
  43. sb.WriteString(" ")
  44. sb.WriteString(strings.Join(info.Features, " "))
  45. }
  46. return sb.String()
  47. }
  48. func init() {
  49. info = Info{
  50. Version: version,
  51. CommitHash: commit,
  52. BuildDate: date,
  53. }
  54. }
  55. // AddFeature adds a feature description
  56. func AddFeature(feature string) {
  57. info.Features = append(info.Features, feature)
  58. }
  59. // Get returns the Info struct
  60. func Get() Info {
  61. return info
  62. }