差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン最新のリビジョン両方とも次のリビジョン | ||
golang [2023/07/17 06:56] – 以前のリビジョンを復元 (2023/07/17 06:10) ともやん | golang [2023/07/17 08:59] – [gotop] ともやん | ||
---|---|---|---|
行 155: | 行 155: | ||
===== プログラムの作成 ===== | ===== プログラムの作成 ===== | ||
- | Go でプログラムを作成するには、$GOPATH/ | + | 公式: [[https:// |
- | <code> | + | \\ |
- | $ mkdir -p $GOPATH/ | + | Go でプログラムを作成するには、< |
- | $ vi hello.go | + | go.mod ファイルを作成してコードの依存関係追跡を有効にする。\\ |
- | </code> | + | <WRAP color_term> |
- | <code go hello.go> | + | <WRAP color_command>< |
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | go: creating new go.mod: module example/ | ||
+ | go: to add module requirements and sums: | ||
+ | go mod tidy | ||
+ | |||
+ | </pre></ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | gmodule example/ | ||
+ | |||
+ | go 1.20 | ||
+ | |||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_mincode> | ||
package main | package main | ||
行 166: | 行 188: | ||
func main() { | func main() { | ||
- | fmt.Println(" | + | fmt.Println(" |
} | } | ||
- | </ | + | </code></ |
+ | </WRAP> | ||
- | 変更を保存し、同じディレクトリで | + | 変更を保存し、同じディレクトリで |
- | <code> | + | <WRAP color_term> |
- | $ go run hello.go | + | <WRAP color_command>< |
- | Hello, World! | + | <b class=GRN> |
- | </code> | + | </ |
+ | <WRAP color_result>< | ||
+ | Haruo, World! | ||
+ | </pre></ | ||
+ | </WRAP> | ||
hello.go をビルドするは簡単である。\\ | hello.go をビルドするは簡単である。\\ | ||
- | <code> | + | <WRAP color_term> |
- | $ go build | + | <WRAP color_command>< |
- | $ ls | + | <b class=GRN> |
- | hello hello.go | + | <b class=GRN> |
- | $ ./hello | + | </ |
- | Hello, World! | + | <WRAP color_result>< |
- | </code> | + | go.mod |
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | Haruo, World! | ||
+ | </pre></ | ||
+ | </WRAP> | ||
さらに **go install** で **$GOPATH/ | さらに **go install** で **$GOPATH/ | ||
- | <code> | + | <WRAP color_term> |
- | $ go install | + | <WRAP color_command>< |
- | $ ls $GOPATH/ | + | <b class=GRN> |
- | hello | + | <b class=GRN> |
- | </code> | + | </ |
+ | <WRAP color_result>< | ||
+ | haruo | ||
+ | </ | ||
+ | </WRAP> | ||
また、**$GOPATH/ | また、**$GOPATH/ | ||
プログラムは **$GOPATH/ | プログラムは **$GOPATH/ | ||
- | <code> | + | <WRAP color_term> |
- | $ echo ' | + | <WRAP color_command>< |
- | $ source ~/.bashrc | + | <b class=GRN> |
- | $ hello | + | <b class=GRN> |
- | Hello, World! | + | <b class=GRN> |
- | </code> | + | </ |
+ | <WRAP color_result>< | ||
+ | Haruo, World! | ||
+ | </pre></ | ||
+ | </WRAP> | ||
===== Go パッケージのインストール ===== | ===== Go パッケージのインストール ===== | ||
+ | Go パッケージは **go install** コマンドでインストールできる。\\ | ||
+ | |||
+ | ==== gotop ==== | ||
+ | <WRAP # | ||
+ | {{: | ||
+ | </ | ||
+ | < | ||
+ | const video = document.getElementById(' | ||
+ | video.setAttribute(' | ||
+ | video.setAttribute(' | ||
+ | video.addEventListener(" | ||
+ | setTimeout(function() { | ||
+ | video.play(); | ||
+ | }, 1); | ||
+ | }); | ||
+ | </ | ||
+ | [[git> | ||
+ | \\ | ||
+ | Go 1.17 から < | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | go: go.mod file not found in current directory or any parent directory. | ||
+ | 'go get' is no longer supported outside a module. | ||
+ | To build and install a command, use 'go install' | ||
+ | like 'go install example.com/ | ||
+ | For more information, | ||
+ | or run 'go help get' or 'go help install' | ||
+ | |||
+ | </ | ||
+ | </ | ||
- | ==== アップストリームの Go パッケージ ==== | + | < |
- | アップストリームプロジェクトは **go get** コマンドでインストールできる。\\ | + | <WRAP color_term> |
- | <code> | + | <WRAP color_command>< |
- | $ go get github.com/gorilla/context | + | <b class=GRN> |
- | </code> | + | </pre></ |
- | ゴ、ゴリラ? | + | <WRAP color_result>< |
+ | go: downloading github.com/ | ||
+ | go: downloading github.com/ | ||
+ | go: downloading github.com/ | ||
+ | go: downloading github.com/ | ||
+ | go: downloading github.com/ | ||
+ | go: downloading github.com/ | ||
+ | go: downloading github.com/ | ||
+ | go: downloading github.com/ | ||
+ | go: downloading github.com/ | ||
+ | go: downloading golang.org/ | ||
+ | </ | ||
+ | </ | ||
+ | gotop を実行する。\\ | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | </ | ||
===== 参考文献 ===== | ===== 参考文献 ===== |