File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ package builtin_
2+
3+ import "fmt"
4+
5+ // PrintFunc は、ビルドイン関数のprintとfmt.Printの違いについてのサンプルです.
6+ func PrintFunc () error {
7+ // ------------------------------------------------------------
8+ // ビルドイン関数の print() と fmt.Print() の違い
9+ //
10+ // ビルドイン関数の print(), println() は標準エラーに出力する
11+ // fmt.PrintXX は、標準出力に出力する
12+ //
13+ // ビルトイン関数の方は、fmtパッケージをimportする必要がないため
14+ // アプリのブート時やデバッグ目的に利用すると便利。
15+ //
16+ // ただし、ビルドイン関数である print(), println() のコメントには
17+ // 以下の一文が記載されている。(builtin/builtin.goより)
18+ // "it is not guaranteed to stay in the language."
19+ // ------------------------------------------------------------
20+ var (
21+ message = "helloworld"
22+ )
23+
24+ // fmtパッケージの方は標準出力に出力する
25+ fmt .Println ("[fmt ]" , message )
26+
27+ // ビルトインの方は標準エラーに出力する
28+ println ("[builtin]" , message )
29+
30+ return nil
31+ }
Original file line number Diff line number Diff line change 66 "github.com/devlights/try-golang/advanced/reflection"
77 "github.com/devlights/try-golang/advanced/sets"
88 "github.com/devlights/try-golang/basic/array_"
9+ "github.com/devlights/try-golang/basic/builtin_"
910 "github.com/devlights/try-golang/basic/comments"
1011 "github.com/devlights/try-golang/basic/constants"
1112 "github.com/devlights/try-golang/basic/defer_"
@@ -46,6 +47,7 @@ func NewSampleMapping() SampleMapping {
4647
4748// MakeMapping は、マッピング生成します
4849func (m SampleMapping ) MakeMapping () {
50+ m ["builtin_print" ] = builtin_ .PrintFunc
4951 m ["error_basic" ] = error_ .Basic
5052 m ["error_sentinel" ] = error_ .Sentinel
5153 m ["error_typeassertion" ] = error_ .TypeAssertion
You can’t perform that action at this time.
0 commit comments