File tree Expand file tree Collapse file tree 6 files changed +55
-0
lines changed
Expand file tree Collapse file tree 6 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ # サンプルリスト
2+
3+ このディレクトリには以下のサンプルがあります。
4+
5+ | file| example name| note|
6+ | ----| ------------| ----|
7+ | embed\_ string.go| embed\_ string| iota の基本的な使い方のサンプルです.|
8+
Original file line number Diff line number Diff line change 1+ /*
2+ Package embeds -- embed パッケージについてのサンプルが配置されているパッケージです。
3+ */
4+ package embeds
Original file line number Diff line number Diff line change 1+ package embeds
2+
3+ import (
4+ _ "embed" // Go1.16 の embed パッケージを利用するために必要な import
5+
6+ "github.com/devlights/gomy/output"
7+ )
8+
9+ //go:embed helloworld.txt
10+ var s string // helloworld.txt の中身が string として設定される
11+
12+ // EmbedString は、embed パッケージの機能を確認するサンプルです (文字列として値を取得)
13+ func EmbedString () error {
14+ //
15+ // go:embed で指定されている部分は、コンパイル時に埋め込みが施される
16+ // なので、プログラム実行時には既に値は変数に設定済みとなっている.
17+ //
18+ output .Stdoutl ("[helloworld.txt]" , s )
19+ return nil
20+ }
Original file line number Diff line number Diff line change 1+ package embeds
2+
3+ import (
4+ "github.com/devlights/try-golang/pkg/mappings"
5+ )
6+
7+ type (
8+ register struct {}
9+ )
10+
11+ // NewRegister -- このパッケージ用のサンプルを登録する mappings.Register を生成します。
12+ func NewRegister () mappings.Register {
13+ return new (register )
14+ }
15+
16+ // Regist -- 登録します.
17+ func (r * register ) Regist (m mappings.ExampleMapping ) {
18+ m ["embed_string" ] = EmbedString
19+ }
Original file line number Diff line number Diff line change 1+ hello
2+ world
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
1212 "github.com/devlights/try-golang/internal/examples/basic/convert"
1313 "github.com/devlights/try-golang/internal/examples/basic/cryptos"
1414 "github.com/devlights/try-golang/internal/examples/basic/defers"
15+ "github.com/devlights/try-golang/internal/examples/basic/embeds"
1516 "github.com/devlights/try-golang/internal/examples/basic/enum"
1617 "github.com/devlights/try-golang/internal/examples/basic/errs"
1718 "github.com/devlights/try-golang/internal/examples/basic/fileio"
@@ -72,6 +73,7 @@ func (r *register) Regist(m mappings.ExampleMapping) {
7273 convert .NewRegister ().Regist (m )
7374 cryptos .NewRegister ().Regist (m )
7475 defers .NewRegister ().Regist (m )
76+ embeds .NewRegister ().Regist (m )
7577 enum .NewRegister ().Regist (m )
7678 errs .NewRegister ().Regist (m )
7779 fileio .NewRegister ().Regist (m )
You can’t perform that action at this time.
0 commit comments