MCPcopy Index your code
hub / github.com/subtrace/subtrace / Full

Function Full

cmd/version/version.go:102–155  ·  view source on GitHub ↗
(isJSON bool)

Source from the content-addressed store, hash-verified

100}
101
102func Full(isJSON bool) string {
103 buildGoVersion, buildOS, buildArch := "unknown", "unknown", "unknown"
104 if info, ok := debug.ReadBuildInfo(); ok {
105 buildGoVersion = info.GoVersion
106 for _, s := range info.Settings {
107 switch s.Key {
108 case "GOOS":
109 buildOS = s.Value
110 case "GOARCH":
111 buildArch = s.Value
112 }
113 }
114 }
115
116 kernelName, kernelVersion, kernelArch := "Unknown", "unknown", "unknown"
117 var buf unix.Utsname
118 if err := unix.Uname(&buf); err == nil {
119 kernelName = cstr(buf.Sysname[:])
120 kernelVersion = cstr(buf.Release[:])
121 kernelArch = cstr(buf.Machine[:])
122 }
123
124 effectiveCaps := GetEffectiveCaps()
125
126 b := new(bytes.Buffer)
127 if isJSON {
128 enc := json.NewEncoder(b)
129 enc.SetIndent("", " ")
130 enc.Encode(map[string]any{
131 "release": Release,
132 "commitHash": CommitHash,
133 "commitTime": CommitTime,
134 "buildTime": BuildTime,
135 "buildGoVersion": buildGoVersion,
136 "buildOS": buildOS,
137 "buildArch": buildArch,
138 "executableHash": getExecutableHash(),
139 "kernelName": kernelName,
140 "kernelVersion": kernelVersion,
141 "kernelArch": kernelArch,
142 "uid": os.Getuid(),
143 "gid": os.Getuid(),
144 "effectiveCaps": effectiveCaps,
145 })
146 } else {
147 fmt.Fprintf(b, "%s\n", Release)
148 fmt.Fprintf(b, " commit %s at %s\n", CommitHash, CommitTime)
149 fmt.Fprintf(b, " built with %s %s/%s at %s hash %s\n", buildGoVersion, buildOS, buildArch, BuildTime, getExecutableHash())
150 fmt.Fprintf(b, " kernel %s %s on %s\n", kernelName, kernelVersion, kernelArch)
151 fmt.Fprintf(b, " running on %s/%s with uid %d gid %d\n", runtime.GOOS, runtime.GOARCH, os.Geteuid(), os.Getgid())
152 fmt.Fprintf(b, " effective caps %s", effectiveCaps)
153 }
154 return b.String()
155}

Callers 2

panicGuardMethod · 0.92
entrypointMethod · 0.85

Calls 4

cstrFunction · 0.85
getExecutableHashFunction · 0.85
GetEffectiveCapsFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected