差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
golang [2023/07/17 06:38] – [Go 関連] ともやん | golang [2023/07/17 09:18] (現在) – [Go のワークスペース (GOPATH 環境変数)] ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
< | < | ||
< | < | ||
- | # | + | # |
- | display: block; | + | |
height: 10rem; | height: 10rem; | ||
max-height: 200px; | max-height: 200px; | ||
- | width: 250px; | + | width: 250px;*/ |
margin: 0 auto; | margin: 0 auto; | ||
object-fit: cover; | object-fit: cover; | ||
行 36: | 行 36: | ||
本家: [[https:// | 本家: [[https:// | ||
ソースコード: | ソースコード: | ||
- | <WRAP youtube>< | + | <WRAP multi-columns # |
+ | <WRAP youtube | ||
<iframe width=" | <iframe width=" | ||
allow=" | allow=" | ||
- | </ | + | </ |
Go はプログラミング言語の 1 つである。(コンパイラー言語) 2009 年、Google で Robert Griesemer、ロブ・パイク、ケン・トンプソンによって設計された。Go は、静的型付け、C言語の伝統に則ったコンパイル言語、メモリ安全性、ガベージコレクション、構造的型付け、CSP スタイルの並行性などの特徴を持つ。Go のコンパイラ、ツール、およびソースコードは、すべてフリーかつオープンソースである。\\ | Go はプログラミング言語の 1 つである。(コンパイラー言語) 2009 年、Google で Robert Griesemer、ロブ・パイク、ケン・トンプソンによって設計された。Go は、静的型付け、C言語の伝統に則ったコンパイル言語、メモリ安全性、ガベージコレクション、構造的型付け、CSP スタイルの並行性などの特徴を持つ。Go のコンパイラ、ツール、およびソースコードは、すべてフリーかつオープンソースである。\\ | ||
\\ | \\ | ||
行 140: | 行 141: | ||
</ | </ | ||
- | 変更するには以下のように設定する。\\ | + | Go でインストールしたコマンドを使用するには < |
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | / | ||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | / | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | GOPATH を変更するには以下のように設定する。\\ | ||
<WRAP color_term> | <WRAP color_term> | ||
<WRAP color_command>< | <WRAP color_command>< | ||
行 154: | 行 175: | ||
===== プログラムの作成 ===== | ===== プログラムの作成 ===== | ||
- | 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 | ||
行 165: | 行 208: | ||
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** コマンドでインストールできる。\\ | ||
- | ==== アップストリームの Go パッケージ | + | ==== gotop ==== |
- | アップストリームプロジェクトは **go get** コマンドでインストールできる。\\ | + | <WRAP # |
- | <code> | + | {{: |
- | $ go get github.com/gorilla/context | + | </ |
- | </code> | + | < |
- | ゴ、ゴリラ? | + | 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> | ||
+ | </pre></ | ||
+ | <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' | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <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> | ||
+ | </ | ||
+ | </ | ||
===== 参考文献 ===== | ===== 参考文献 ===== |