824
return uuid.ParseBytes(uuidFileBytes)
825
}
826
827
+// CustomVersion is an optional string that overrides Caddy's
828
+// reported version. It can be helpful when downstream packagers
829
+// need to manually set Caddy's version. If no other version
830
+// information is available, the short form version (see
831
+// Version()) will be set to CustomVersion, and the full version
832
+// will include CustomVersion at the beginning.
833
+//
834
+// Set this variable during `go build` with `-ldflags`:
835
+//
836
+// -ldflags '-X github.com/caddyserver/caddy/v2.CustomVersion=v2.6.2'
837
+//
838
+// for example.
839
+var CustomVersion string
840
+
841
// Version returns the Caddy version in a simple/short form, and
842
// a full version string. The short form will not have spaces and
843
// is intended for User-Agent strings and similar, but may be
847
// build info provided by go.mod dependencies; then it tries to
848
// get info from embedded VCS information, which requires having
849
// built Caddy from a git repository. If no version is available,
836
-// this function returns "(devel)" becaise Go uses that, but for
837
-// the simple form we change it to "unknown".
850
+// this function returns "(devel)" because Go uses that, but for
851
+// the simple form we change it to "unknown". If still no version
852
+// is available (e.g. no VCS repo), then it will use CustomVersion;
853
+// CustomVersion is always prepended to the full version string.
854
//
855
// See relevant Go issues: https://github.com/golang/go/issues/29228
856
// and https://github.com/golang/go/issues/50603.
926
}
927
}
928
929
+ if full == "" {
930
+ if CustomVersion != "" {
931
+ full = CustomVersion
932
+ } else {
933
+ full = "unknown"
934
+ }
935
+ } else if CustomVersion != "" {
936
+ full = CustomVersion + " " + full
937
+ }
938
+
939
if simple == "" || simple == "(devel)" {
914
- simple = "unknown"
940
+ if CustomVersion != "" {
941
+ simple = CustomVersion
942
+ } else {
943
+ simple = "unknown"
944
+ }
945
}
946
947
return