差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
golang [2021/03/27 15:04] – [参考文献] ともやん | 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; | ||
行 37: | 行 37: | ||
ソースコード: | ソースコード: | ||
<WRAP multi-columns # | <WRAP multi-columns # | ||
- | < | + | < |
- | {{:golang: | + | < |
- | </ | + | |
+ | </ | ||
Go はプログラミング言語の 1 つである。(コンパイラー言語) 2009 年、Google で Robert Griesemer、ロブ・パイク、ケン・トンプソンによって設計された。Go は、静的型付け、C言語の伝統に則ったコンパイル言語、メモリ安全性、ガベージコレクション、構造的型付け、CSP スタイルの並行性などの特徴を持つ。Go のコンパイラ、ツール、およびソースコードは、すべてフリーかつオープンソースである。\\ | Go はプログラミング言語の 1 つである。(コンパイラー言語) 2009 年、Google で Robert Griesemer、ロブ・パイク、ケン・トンプソンによって設計された。Go は、静的型付け、C言語の伝統に則ったコンパイル言語、メモリ安全性、ガベージコレクション、構造的型付け、CSP スタイルの並行性などの特徴を持つ。Go のコンパイラ、ツール、およびソースコードは、すべてフリーかつオープンソースである。\\ | ||
\\ | \\ | ||
行 47: | 行 48: | ||
===== インストール ===== | ===== インストール ===== | ||
- | Fedora では最新版の | + | 公式: [[https:// |
- | 2019/09/17 現在の Go の最新バージョンは v1.12.9 である。\\ | + | <WRAP color_term> |
- | Fedora Linux on WSL 2\\ | + | <WRAP color_command>< |
- | <code> | + | <b class=GRN> |
- | $ sudo dnf install | + | </ |
- | $ go version | + | <WRAP color_result_long>< |
- | go version go1.12.9 linux/amd64 | + | Fedora 38 - x86_64 - Updates |
- | </code> | + | Fedora 38 - x86_64 - Updates |
+ | Fedora Modular 38 - x86_64 - Updates | ||
+ | 依存関係が解決しました。 | ||
+ | ============================================================================================================== | ||
+ | | ||
+ | ============================================================================================================== | ||
+ | インストール: | ||
+ | <b class=GRN> | ||
+ | 依存関係のインストール: | ||
+ | <b class=GRN>golang-bin | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | 弱い依存関係のインストール: | ||
+ | <b class=GRN> | ||
- | GOPATH 環境変数を設定する。\\ | + | トランザクションの概要 |
- | <code> | + | ============================================================================================================== |
- | $ mkdir -p ~/go | + | インストール |
- | $ echo ' | + | |
- | $ source ~/.bashrc | + | ダウンロードサイズの合計: |
- | $ go env GOPATH | + | インストール後のサイズ: |
+ | これでよろしいですか? [y/N]: y | ||
+ | パッケージのダウンロード: | ||
+ | (1/7): libserf-1.3.9-27.fc38.x86_64.rpm | ||
+ | (2/7): utf8proc-2.7.0-4.fc38.x86_64.rpm | ||
+ | (3/7): subversion-1.14.2-13.fc38.x86_64.rpm | ||
+ | (4/7): subversion-libs-1.14.2-13.fc38.x86_64.rpm | ||
+ | (5/7): golang-1.20.5-1.fc38.x86_64.rpm | ||
+ | (6/7): golang-src-1.20.5-1.fc38.noarch.rpm | ||
+ | (7/7): golang-bin-1.20.5-1.fc38.x86_64.rpm | ||
+ | -------------------------------------------------------------------------------------------------------------- | ||
+ | 合計 | ||
+ | トランザクションの確認を実行中 | ||
+ | トランザクションの確認に成功しました。 | ||
+ | トランザクションのテストを実行中 | ||
+ | トランザクションのテストに成功しました。 | ||
+ | トランザクションを実行中 | ||
+ | scriptletの実行中: | ||
+ | 準備 | ||
+ | インストール中 | ||
+ | インストール中 | ||
+ | インストール中 | ||
+ | インストール中 | ||
+ | インストール中 | ||
+ | scriptletの実行中: | ||
+ | インストール中 | ||
+ | インストール中 | ||
+ | scriptletの実行中: | ||
+ | 検証 | ||
+ | 検証 | ||
+ | 検証 | ||
+ | 検証 | ||
+ | 検証 | ||
+ | 検証 | ||
+ | 検証 | ||
+ | |||
+ | インストール済み: | ||
+ | golang-1.20.5-1.fc38.x86_64 | ||
+ | libserf-1.3.9-27.fc38.x86_64 | ||
+ | utf8proc-2.7.0-4.fc38.x86_64 | ||
+ | |||
+ | 完了しました! | ||
+ | |||
+ | </ | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | go version go1.20.5 linux/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== Go のワークスペース (GOPATH | ||
+ | 公式: [[https://go.dev/ | ||
+ | Go のワークスペースは標準で < | ||
+ | <WRAP color_term> | ||
+ | <WRAP color_command>< | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
/ | / | ||
- | </ | + | </pre></ |
+ | </ | ||
+ | |||
+ | 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_command>< | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | <b class=GRN> | ||
+ | </ | ||
+ | <WRAP color_result>< | ||
+ | / | ||
+ | </ | ||
+ | </WRAP> | ||
===== プログラムの作成 ===== | ===== プログラムの作成 ===== | ||
- | 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 | ||
行 77: | 行 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> | ||
+ | </ | ||
+ | </ | ||
===== 参考文献 ===== | ===== 参考文献 ===== | ||
行 133: | 行 336: | ||
[[https:// | [[https:// | ||
+ | ==== 付録 ==== | ||
+ | [[tw> | ||