This commit is contained in:
ptux 2022-07-31 08:12:22 +09:00
parent da65bbac57
commit 4aaf2f0249
2 changed files with 35 additions and 34 deletions

View File

@ -1,87 +1,88 @@
---
title: '#90DaysOfDevOps - The Go Workspace - Day 10'
title: '#90DaysOfDevOps - Goワークスペースとコードのコンパイルと実行 - 10日目'
published: false
description: 90DaysOfDevOps - The Go Workspace
description: 90DaysOfDevOps - Goワークスペースとコードのコンパイルと実行
tags: "devops, 90daysofdevops, learning"
cover_image: null
canonical_url: null
id: 1048701
---
### The Go Workspace
On [Day 8](day08.md) we briefly covered the Go workspace to get Go up and running to get to the demo of `Hello #90DaysOfDevOps` But we should explain a little more about the Go workspace.
### Goワークスペースとコードのコンパイルと実行
[Day 8](day08.md) では、`Hello #90DaysOfDevOps` のデモを行うためにGoを起動するためのGoワークスペースを簡単に説明しましたが、Goワークスペースについてもう少し説明する必要があると思います。
Remember we chose the defaults and we then went through and created our Go folder in the GOPATH that was already defined but in reality, this GOPATH can be changed to be wherever you want it to be.
If you run
私たちはデフォルトを選択し、すでに定義されているGOPATHにGoフォルダを作成したことを思い出してください。
```
echo $GOPATH
```
The output should be similar to mine (with a different username may be) which is:
```
を実行すると 出力は私のものと似ているはずです(ユーザー名は違うかもしれませんが)。
```
/home/michael/projects/go
```
Then within here, we created 3 directories. **src**, **pkg** and **bin**
そして、この中に、3つのディレクトリを作成しました。**src**, **pkg**, **bin** の3つのディレクトリを作成しました。
![](Images/Day10_Go1.png)
**src** is where all of your Go programs and projects are stored. This handles namespacing package management for all your Go repositories. This is where you will see on our workstation we have our Hello folder for the Hello #90DaysOfDevOps project.
**src** は、すべての Go プログラムとプロジェクトが保存される場所です。これは、すべてのGoリポジトリの名前空間パッケージ管理を処理します。ここでは、ワークステーションにHello #90DaysOfDevOpsプロジェクト用のHelloフォルダがあることがわかります
![](Images/Day10_Go2.png)
**pkg** is where your archived files of packages that are or were installed in programs. This helps to speed up the compiling process based on if the packages being used have been modified.
**pkg** は、プログラムにインストールされている、またはインストールされていたパッケージの アーカイブファイルです。これは、使用されているパッケージが変更されたかどうかに基づいて、コンパイル処理を高速化するのに役立ちます。
![](Images/Day10_Go3.png)
**bin** is where all of your compiled binaries are stored.
**bin** は、コンパイルされたすべてのバイナリが格納される場所です。
![](Images/Day10_Go4.png)
Our Hello #90DaysOfDevOps is not a complex program so here is an example of a more complex Go Program taken from another great resource worth looking at [GoChronicles](https://gochronicles.com/)
Hello #90DaysOfDevOps は複雑なプログラムではないので、別の素晴らしいリソース [GoChronicles](https://gochronicles.com/) から引用した、より複雑な Go プログラムの例を紹介します。
![](Images/Day10_Go5.png)
This page also goes into some great detail about why and how the layout is like this it also goes a little deeper on other folders we have not mentioned [GoChronicles](https://gochronicles.com/project-structure/)
このページでは、なぜこのようなレイアウトになっているのか、また、私たちが言及していない他のフォルダーについても少し詳しく説明しています [GoChronicles](https://gochronicles.com/project-structure/)
### Compiling & running code
On [Day 9](day09.md) we also covered a brief introduction to compiling code, but we can go a little deeper here.
### コードのコンパイル&実行
To run our code we first must **compile** it. There are three ways to do this within Go.
Day 9](day09.md) では、コードのコンパイルについて簡単に紹介しましたが、ここではもう少し深く掘り下げます。
- go build
- go install
コードを実行するには、まず **コンパイル** しなければなりません。Goの中でこれを行うには、3つの方法があります。
- go ビルド
- インストールする
- go run
Before we get to the above compile stage we need to take a look at what we get with the Go Installation.
上記のコンパイル段階に入る前に、Goのインストールで得られるものを見ておく必要があります。
When we installed Go on Day 8 this installed something known as Go tools which consist of several programs that let us build and process our Go source files. One of the tools is `Go`
8日目にGoをインストールしたとき、Goツールというものがインストールされました。これはGoのソースファイルをビルドしたり処理したりするためのいくつかのプログラムで構成されています。ツールの1つが `Go` です。
It is worth noting that you can install additional tools that are not in the standard Go installation.
特筆すべきは、標準的なGoのインストールには含まれていない、追加のツールをインストールすることができることです。
If you open your command prompt and type `go` you should see something like the image below and then you will see "Additional Help Topics" below that for now we don't need to worry about those.
コマンドプロンプトを開いて `go` と入力すると、下の画像のようなものが表示され、その下に "Additional Help Topics" と表示されますが、今のところ気にする必要はありません。
![](Images/Day10_Go6.png)
You might also remember that we have already used at least two of these tools so far on Day 8.
また、これらのツールのうち少なくとも2つは、8日目までにすでに使っていることを思い出してください。
![](Images/Day10_Go7.png)
The ones we want to learn more about are build, install and run.
もっと詳しく知りたいのは、ビルド、インストール、ランです。
![](Images/Day10_Go8.png)
- `go run` - This command compiles and runs the main package comprised of the .go files specified on the command line. The command is compiled to a temporary folder.
- `go build` - To compile packages and dependencies, compile the package in the current directory. If the `main` package, will place the executable in the current directory if not then it will place the executable in the `pkg` folder. `go build` also enables you to build an executable file for any Go Supported OS platform.
- `go install` - The same as go build but will place the executable in the `bin` folder
- `go run` - このコマンドは、コマンドラインで指定された .go ファイルで構成されるメインパッケージをコンパイルして実行します。このコマンドは、一時フォルダにコンパイルされます。
- `go build` - パッケージと依存関係をコンパイルするために、カレントディレクトリにあるパッケージをコンパイルします。main` パッケージであれば、カレントディレクトリに実行ファイルを配置します。そうでなければ、`pkg` フォルダに実行ファイルを配置します。また、`go build` を使うと、Go がサポートする OS プラットフォーム用の実行ファイルをビルドすることができます。
- go install` - go build と同じですが、実行ファイルを `bin` フォルダに配置します。
We have run through go build and go run but feel free to run through them again here if you wish, `go install` as stated above puts the executable in our bin folder.
go build と go run を実行しましたが、必要であればここでもう一度実行しても構いません。
![](Images/Day10_Go9.png)
Hopefully, if you are following along you are watching one of the playlists or videos below, I am taking bits of all of these and translating these into my notes so that I can understand the foundational knowledge of the Golang language. The resources below are likely going to give you a much better understanding of a lot of the areas you need overall but I am trying to document the 7 days or 7 hours worth of the journey with interesting things that I have found.
もしあなたがフォローしているなら、以下のプレイリストやビデオのいずれかを見ていることを希望的観測として、私はこれら全ての断片を取り、Golang言語の基礎知識を理解できるようにこれらを私のメモに翻訳しています。以下のリソースは、あなたが全体的に必要とする多くの分野について、より良い理解を与えてくれそうですが、私は7日間または7時間分の旅の記録として、私が見つけた面白いことを記録しようとしています。
## Resources
## リソース
- [StackOverflow 2021 Developer Survey](https://insights.stackoverflow.com/survey/2021)
- [Why we are choosing Golang to learn](https://www.youtube.com/watch?v=7pLqIIAqZD4&t=9s)
@ -91,4 +92,4 @@ Hopefully, if you are following along you are watching one of the playlists or v
- [FreeCodeCamp - Learn Go Programming - Golang Tutorial for Beginners](https://www.youtube.com/watch?v=YS4e4q9oBaU&t=1025s)
- [Hitesh Choudhary - Complete playlist](https://www.youtube.com/playlist?list=PLRAV69dS1uWSR89FRQGZ6q9BR2b44Tr9N)
See you on [Day 11](day11.md).
[11日目](day11.md)にお会いしましょう。

View File

@ -31,7 +31,7 @@ English Version | [中文版本](zh_cn/README.md) | [繁體中文版本](zh_tw/R
- [✔️] ⌨️ 7 > [The Big Picture: DevOps & Learning a Programming Language](Days/day07.md)
- [✔️] ⌨️ 8 > [GoとHello WorldのためのDevOps環境のセットアップ](Days/day08.md)
- [✔️] ⌨️ 9 > [Let's explain the Hello World code](Days/day09.md)
- [✔️] ⌨️ 10 > [The Go Workspace & Compiling & running code](Days/day10.md)
- [✔️] ⌨️ 10 > [Goワークスペースとコードのコンパイルと実行](Days/day10.md)
- [✔️] ⌨️ 11 > [Variables, Constants & Data Types](Days/day11.md)
- [✔️] ⌨️ 12 > [Getting user input with Pointers and a finished program](Days/day12.md)
- [✔️] ⌨️ 13 > [Tweet your progress with our new App](Days/day13.md)