-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
library.go
44 lines (36 loc) · 865 Bytes
/
library.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package slogparquet
import (
"runtime/debug"
"strings"
)
const library = "samber/slog-parquet"
const goModulePath = "github.com/" + library
var semver = "v0.0.0"
var buildSHA1 = "xxxxx"
func init() {
build, ok := debug.ReadBuildInfo()
if !ok {
return
}
for _, mod := range build.Deps {
if mod.Replace == nil && mod.Path == goModulePath {
semver, _, buildSHA1 = parseModuleVersion(mod.Version)
break
}
}
}
func parseModuleVersion(version string) (semver, datetime, buildsha string) {
semver, version = splitModuleVersion(version)
datetime, version = splitModuleVersion(version)
buildsha, _ = splitModuleVersion(version)
semver = strings.TrimPrefix(semver, "v")
return
}
func splitModuleVersion(s string) (head, tail string) {
if i := strings.IndexByte(s, '-'); i < 0 {
head = s
} else {
head, tail = s[:i], s[i+1:]
}
return
}