File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed
Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package runtimes
33import (
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}
You can’t perform that action at this time.
0 commit comments