Skip to content

Commit 47c2abb

Browse files
committed
Update basic/runtimes/version.go
1 parent b52ce70 commit 47c2abb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

examples/basic/runtimes/version.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package runtimes
33
import (
44
"fmt"
55
"runtime"
6+
"runtime/debug"
67
)
78

89
// RuntimeVersion は、runtime.Version() のサンプルです。
@@ -11,20 +12,28 @@ func RuntimeVersion() error {
1112
ver := runtime.Version()
1213
fmt.Println(ver)
1314

15+
// debug.ReadBuildInfo() からも取得することが出来る
16+
info, ok := debug.ReadBuildInfo()
17+
if !ok {
18+
return fmt.Errorf("failed: debug.ReadBuildInfo()")
19+
}
20+
fmt.Println(info.GoVersion)
21+
1422
return nil
1523

1624
/*
17-
$ task
18-
task: Task "build" is up to date
19-
task: [run] ./try-golang -onetime
25+
$ task
26+
task: [build] go build -o "/workspace/try-golang/try-golang" .
27+
task: [run] ./try-golang -onetime
2028
21-
ENTER EXAMPLE NAME: runtime_version
29+
ENTER EXAMPLE NAME: runtime_version
2230
23-
[Name] "runtime_version"
24-
go1.21.6
31+
[Name] "runtime_version"
32+
go1.23.5
33+
go1.23.5
2534
2635
27-
[Elapsed] 3.21µs
36+
[Elapsed] 48.21µs
2837
*/
2938

3039
}

0 commit comments

Comments
 (0)