Merge branch 'main' into ja-day12

This commit is contained in:
Wang 2022-08-09 14:33:12 +09:00 committed by GitHub
commit e9784faaf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 164 additions and 156 deletions

View File

@ -84,7 +84,7 @@ I have also placed a copy of this specific vagrant file in the [Linux Folder](Li
## Provisioning our Linux Desktop
We are now ready to get our first machine up and running, in our workstation's terminal. In my case I am using PowerShell on my Windows machine. Navigate to your projects folder and where you will find your VAGRANTFILE. Once there you can type the command `vagrant up` and if everything's allright you will see something like this.
We are now ready to get our first machine up and running, in our workstation's terminal. In my case I am using PowerShell on my Windows machine. Navigate to your projects folder and where you will find your VAGRANTFILE. Once there you can type the command `vagrant up` and if everything's alright you will see something like this.
![](Images/Day14_Linux2.png)

View File

@ -1,60 +1,60 @@
---
title: '#90DaysOfDevOps - The Big Picture: Learning a Programming Language - Day 7'
title: '#90DaysOfDevOps - 全体像: DevOpsとプログラミング言語の学習 - 7日目'
published: false
description: 90DaysOfDevOps - The Big Picture DevOps & Learning a Programming Language
description: 90DaysOfDevOps - 体像: DevOpsとプログラミング言語の学習
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048856
---
## The Big Picture: DevOps & Learning a Programming Language
## 体像: DevOpsとプログラミング言語の学習
I think it is fair to say to be successful in the long term as a DevOps engineer you've got to know at least one programming language at a foundational level. I want to take this first session of this section to explore why this is such a critical skill to have, and hopefully, by the end of this week or section, you are going to have a better understanding of the why, how and what to do to progress with your learning journey.
DevOpsエンジニアとして長期的に成功するためには、少なくとも1つのプログラミング言語を基礎的なレベルで知っておく必要がある、と言ってもいいと思います。最初のセッションでは、なぜこのような重要なスキルが必要なのかを探ります。この週やセクションが終わる頃には、なぜ、どのように、何をすれば学習を進めることができるのかについて、より深く理解できるようになっていることを願っています。
I think if I was to ask out on social do you need to have programming skills for DevOps related roles, the answer will be most likely a hard yes? Let me know if you think otherwise? Ok but then a bigger question and this is where you won't get such a clear answer is which programming language? The most common answer I have seen here has been Python or increasingly more often, we're seeing Golang or Go should be the language that you learn.
もし私がソーシャル上で「DevOps関連の職務にプログラミングスキルは必要ですか」と尋ねたら、その答えはおそらく「イエス」でしょうそうでない場合は、私に教えてください。しかし、もっと大きな疑問があり、ここで明確な答えが得られないのが、どのプログラミング言語かということです。 ここで私が見た最も一般的な答えはPythonで、最近ではGolangやGoを学ぶべきという意見も増えています。
To be successful in DevOps you have to have a good knowledge of programming skills is my takeaway from that at least. But we have to understand why we need it to choose the right path.
DevOpsで成功するためには、プログラミングスキルに関する十分な知識が必要だというのが、少なくとも私が得た教訓です。しかし、正しい道を選択するためには、なぜそれが必要なのかを理解する必要があります。
## Understand why you need to learn a programming language.
## なぜプログラミング言語を学ぶ必要があるのかを理解する
The reason that Python and Go are recommended so often for DevOps engineers is that a lot of the DevOps tooling is written in either Python or Go, which makes sense if you are going to be building DevOps tools. Now this is important as this will determine really what you should learn and that would likely be the most beneficial. If you are going to be building DevOps tools or you are joining a team that does then it would make sense to learn that same language, if you are going to be heavily involved in Kubernetes or Containers then it's more than likely that you would want to choose Go as your programming language. For me, the company I work for (Kasten by Veeam) is in the Cloud-Native ecosystem focused on data management for Kubernetes and everything is written in Go.
PythonとGoがDevOpsエンジニアに頻繁に推奨される理由は、DevOpsツールの多くがPythonかGoで書かれているからです。このことは、あなたが何を学ぶべきかを決定し、最も有益である可能性が高いので、重要なことです。もしあなたがDevOpsツールを作ろうとしている、あるいは作っているチームに参加しようとしているのなら、同じ言語を学ぶのは理にかなっていますし、もしあなたがKubernetesやコンテナに深く関わっているのなら、プログラミング言語としてGoを選びたいと思うかもしれませんね。私の場合、私が働いている会社Kasten by Veeamは、Kubernetesのデータ管理に焦点を当てたCloud-Nativeエコシステムで、すべてがGoで記述されています。
But then you might not have clear cut reasoning like that to choose you might be a student or transitioning careers with no real decision made for you. I think in this situation then you should choose the one that seems to resonate and fit with the applications you are looking to work with.
しかし、そのような明確な理由がない場合、学生であったり、キャリアの転換期であったりして、本当の意味での決断ができないかもしれません。そんなときは、自分がやりたいアプリケーションに共鳴し、フィットしそうなものを選べばいいと思います。
Remember I am not looking to become a software developer here I just want to understand a little more about the programming language so that I can read and understand what those tools are doing and then that leads to possibly how we can help improve things.
私はソフトウェア開発者になりたいわけではなく、プログラミング言語についてもう少し理解したいだけなのです。
I would also it is also important to know how you interact with those DevOps tools which could be Kasten K10 or it could be Terraform and HCL. These are what we will call config files and this is how you interact with those DevOps tools to make things happen, commonly these are going to be YAML. (We may use the last day of this section to dive a little into YAML)
また、Kasten K10やTerraform、HCLといったDevOpsツールとどのように連携するのかも重要です。これは設定ファイルと呼ばれるもので、DevOpsツールとどのようにやり取りして物事を実現するかというものです。(このセクションの最終日にYAMLについて少し掘り下げます。
## Did I just talk myself out of learning a programming language?
## プログラミング言語の習得を断念したのは、私自身のせい?
Most of the time or depending on the role, you will be helping engineering teams implement DevOps into their workflow, a lot of testing around the application and making sure that the workflow that is built aligns to those DevOps principles we mentioned over the first few days. But in reality, this is going to be a lot of the time troubleshooting an application performance issue or something along those lines. This comes back to my original point and reasoning, the programming language I need to know is the one that the code is written in? If their application is written in NodeJS it wont help much if you have a Go or Python badge.
ほとんどの場合、あるいは職務によっては、エンジニアリングチームがワークフローにDevOpsを導入するのを支援し、アプリケーションに関する多くのテストを行い、構築されたワークフローが最初の数日間で述べたDevOpsの原則に合致していることを確認することになります。しかし実際には、アプリケーションのパフォーマンス問題などのトラブルシューティングを行うことが多いようです。これは、私が知っておくべきプログラミング言語は、コードが書かれている言語なのか、という最初の論点と理由に戻ります。アプリケーションがNodeJSで書かれている場合、GoやPythonのバッジを持っていても、あまり役に立ちません。
## Why Go
## なぜGoを習得するのか
Why Golang is the next programming language for DevOps, Go has become a very popular programming language in recent years. According to the StackOverflow Survey for 2021 Go came in fourth for the most wanted Programming, scripting and markup languages with Python being top but hear me out. [StackOverflow 2021 Developer Survey Most Wanted Link](https://insights.stackoverflow.com/survey/2021#section-most-loved-dreaded-and-wanted-programming-scripting-and-markup-languages)
DevOpsのための次のプログラミング言語がGolangである理由近年、Goは非常に人気のあるプログラミング言語になっています。2021年のStackOverflow Surveyによると、Goは最も欲しいプログラミング、スクリプト、マークアップ言語の第4位で、Pythonがトップですが、私の話を聞いてください。[StackOverflow 2021 Developer Survey - Most Wanted Link](https://insights.stackoverflow.com/survey/2021#section-most-loved-dreaded-and-wanted-programming-scripting-and-markup-languages)
As I have also mentioned some of the most known DevOps tools and platforms are written in Go such as Kubernetes, Docker, Grafana and Prometheus.
また、Kubernetes、Docker、Grafana、Prometheusなど、最も有名なDevOpsツールやプラットフォームがGoで書かれていることも紹介した通りです。
What are some of the characteristics of Go that make it great for DevOps?
DevOpsに最適なGoの特徴にはどのようなものがあるのでしょうか。
## Build and Deployment of Go Programs
An advantage of using a language like Python that is interpreted in a DevOps role is that you dont need to compile a python program before running it. Especially for smaller automation tasks, you dont want to be slowed down by a build process that requires compilation even though, Go is a compiled programming language, **Go compiles directly into machine code**. Go is known also for fast compilation times.
## Goプログラムのビルドとデプロイメント
Pythonのようなインタプリタ言語をDevOpsの役割で使用する利点は、Pythonプログラムを実行する前にコンパイルする必要がないことです。特に小規模な自動化タスクでは、コンパイルが必要なビルドプロセスで時間がかかるのは避けたいものです。 Goはコンパイルが速いことでも知られています。
## Go vs Python for DevOps
## DevOpsにおけるGoとPythonの比較
Go Programs are statically linked, this means that when you compile a go program everything is included in a single binary executable, no external dependencies will be required that would need to be installed on the remote machine, this makes the deployment of go programs easy, compared to python program that uses external libraries you have to make sure that all those libraries are installed on the remote machine that you wish to run on.
Goプログラムは静的にリンクされています。つまり、Goプログラムをコンパイルすると、すべてが単一のバイナリ実行ファイルに含まれ、リモートマシンにインストールする必要のある外部依存は必要ありません。
Go is a platform-independent language, which means you can produce binary executables for *all the operating systems, Linux, Windows, macOS etc and very easy to do so. With Python, it is not as easy to create these binary executables for particular operating systems.
Goはプラットフォームに依存しない言語です。つまり、Linux、Windows、macOSなど*すべてのオペレーティングシステム用のバイナリ実行ファイルを作成することができ、非常に簡単に実行することができます。Pythonでは、特定のオペレーティングシステム用のバイナリ実行ファイルを作成するのはそれほど簡単ではありません。
Go is a very performant language, it has fast compilation and fast run time with lower resource usage like CPU and memory especially compared to python, numerous optimisations have been implemented in the Go language that makes it so performant. (Resources below)
Goは非常にパフォーマンスの高い言語であり、特にPythonと比較してCPUやメモリなどのリソース使用量が少なく、高速なコンパイルと高速な実行が可能で、Go言語には数多くの最適化が実装されているため、非常にパフォーマンスが高い。(下記リソース)
Unlike Python which often requires the use of third party libraries to implement a particular python program, go includes a standard library that has the majority of functionality that you would need for DevOps built directly into it. This includes functionality file processing, HTTP web services, JSON processing, native support for concurrency and parallelism as well as built-in testing.
Pythonでは、特定のPythonプログラムを実装するためにサードパーティのライブラリを使用する必要がありますが、Goには標準ライブラリがあり、DevOpsに必要な機能の大部分が直接組み込まれています。これには、ファイル処理、HTTPウェブサービス、JSON処理、並行処理と並列処理のネイティブサポート、組み込みのテストなどの機能が含まれます。
This is by no way throwing Python under the bus I am just giving my reasons for choosing Go but they are not the above Go vs Python it's generally because it makes sense as the company I work for develops software in Go so that is why.
これは決してPythonを投げつけるわけではなく、私がGoを選んだ理由を述べているのですが、上記のGo vs Pythonということではなく、私が働いている会社がGoでソフトウェアを開発しているので、一般的に理にかなっているから、というのが理由です。
I will say that once you have or at least I am told as I am not many pages into this chapter right now, is that once you learn your first programming language it becomes easier to take on other languages. You're probably never going to have a single job in any company anywhere where you don't have to deal with manage, architect, orchestrating, debug JavaScript and Node JS applications.
この章をまだ読み終えていないのですが、最初のプログラミング言語を習得すると、他の言語への挑戦が容易になると言われています。おそらく、どこの会社でも、JavaScriptやNode JSアプリケーションの管理、アーキテクト、オーケストレーション、デバッグに携わらない仕事はないでしょう。
## 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)
@ -64,6 +64,6 @@ I will say that once you have or at least I am told as I am not many pages into
- [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)
Now for the next 6 days of this topic my intention is to work through some of the resources listed above and document my notes for each day. You will notice that they are generally around 3 hours as a full course, I wanted to share my complete list so that if you have time you should move ahead and work through each one if time permits, I will be sticking to my learning hour each day.
さて、このトピックの次の6日間、私の意図は、上記のリソースのいくつかに取り組んで、毎日の私のートを文書化することです。もし、あなたが時間があれば、先に進み、時間が許す限り、それぞれを学習してください。
See you on [Day 8](day08.md).
それでは、【8日目】(day08.md)でお会いしましょう。

View File

@ -1,71 +1,74 @@
---
title: '#90DaysOfDevOps - Let''s explain the Hello World code - Day 9'
title: '#90DaysOfDevOps - Hello Worldのコードを説明しましょう - 9日目'
published: false
description: 90DaysOfDevOps - Let's explain the Hello World code
description: 90DaysOfDevOps - Hello Worldのコードを説明しましょう
tags: "devops, 90daysofdevops, learning"
cover_image: null
canonical_url: null
id: 1048732
---
## Let's explain the Hello World code
## Hello Worldのコードを説明しましょう
### How Go works
### Go の仕組み
On [Day 8](day08.md) we walked through getting Go installed on your workstation and we then created our first Go application.
[Day 8](day08.md) では、ワークステーションに Go をインストールする方法を説明し、その後最初の Go アプリケーションを作成しました。
In this section, we are going to take a deeper look into the code and understand a few more things about the Go language.
このセクションでは、コードをより深く見て、Go 言語についてもう少し理解します。
### What is Compiling?
Before we get into the [6 lines of the Hello World code](Go/hello.go) we need to have a bit of an understanding about compiling.
Programming languages that we commonly use such as Python, Java, Go and C++ are high-level languages. Meaning they are human-readable but when a machine is trying to execute a program it needs to be in a form that a machine can understand. We have to translate our human-readable code to machine code which is called compiling.
### コンパイルとは?
Hello Worldの6行のコード](Go/hello.go)に入る前に、コンパイルについて少し理解しておく必要があります。
Python、Java、Go、C++など、私たちが普段使っているプログラミング言語は、高水準言語です。つまり、人間が読むことはできても、機械がプログラムを実行するときには、機械が理解できる形である必要があるのです。そのため、人間が読めるコードを機械語に変換する必要があります。これをコンパイルといいます。
![](Images/Day9_Go1.png)
From the above you can see what we did on [Day 8](day08.md) here, we created a simple Hello World main.go and we then used the command `go build main.go` to compile our executable.
上記から、私たちが [Day 8](day08.md) で何をしたかがわかります。ここでは、単純な Hello World main.go を作成し、 `go build main.go` コマンドを使って実行ファイルをコンパイルしています。
### What are packages?
A package is a collection of source files in the same directory that are compiled together. We can simplify this further, a package is a bunch of .go files in the same directory. Remember our Hello folder from Day 8? If and when you get into more complex Go programs you might find that you have folder1 folder2 and folder3 containing different .go files that make up your program with multiple packages.
### パッケージとは何ですか?
パッケージとは、同じディレクトリにあるソースファイルの集まりで、一緒にコンパイルされたものです。さらに単純化すると、パッケージは同じディレクトリにあるたくさんの .go ファイルです。8日目のHelloフォルダーを覚えていますかより複雑な Go プログラムに参加する場合、folder1 folder2 folder3 に異なる .go ファイルがあり、複数のパッケージでプログラムを構成していることに気づくかもしれません。
We use packages so we can reuse other peoples code, we don't have to write everything from scratch. Maybe we are wanting a calculator as part of our program, you could probably find an existing Go Package that contains the mathematical functions that you could import into your code saving you a lot of time and effort in the long run.
パッケージを使うのは、他の人のコードを再利用するためで、すべてを一から書く必要はありません。例えば、プログラムの一部として電卓を使いたい場合、数学関数を含む既存の Go パッケージを見つけることができ、それをコードにインポートすれば、長い目で見れば多くの時間と労力を節約することができます。
Go encourages you to organise your code in packages so that it is easy to reuse and maintain source code.
Go では、ソース コードの再利用と保守を容易にするために、コードをパッケージで整理することを推奨しています。
### Hello #90DaysOfDevOps Line by Line
Now let's take a look at our Hello #90DaysOfDevOps main.go file and walk through the lines.
### Hello #90DaysOfDevOps 行を追う
それでは、Hello #90DaysOfDevOps の main.go ファイルを見て、行を追って見ていきましょう。
![](Images/Day9_Go2.png)
In the first line, you have `package main` which means that this file belongs to a package called main. All .go files need to belong to a package, they should also have `package something` in the opening line.
最初の行に `package main` とありますが、これはこのファイルが main というパッケージに属していることを意味します。すべての .go ファイルはパッケージに属する必要があり、冒頭の行に `package something` と書かれている必要があります。
A package can be named whatever you wish. We have to call this `main` as this is the starting point of the program that is going to be in this package, this is a rule. (I need to understand more about this rule?)
パッケージは好きな名前をつけることができます。このパッケージの中に入るプログラムのスタート地点なので、 `main` と呼ばなければなりません。これは規則です。(このルールについてもっと理解する必要がある?)
![](Images/Day9_Go3.png)
Whenever we want to compile and execute our code we have to tell the machine where the execution needs to start. We do this by writing a function called main. The machine will look for a function called main to find the entry point of the program.
コードをコンパイルして実行するときはいつでも、実行を開始する場所をマシンに伝えなければなりません。これはmainと呼ばれる関数を書くことによって行います。マシンはプログラムのエントリポイントを見つけるためにmainと呼ばれる関数を探します。
A function is a block of code that can do some specific task for and can be used across the program.
関数とは、ある特定のタスクを実行するコードのブロックのことで、プログラム全体で使用することができます。
You can declare a function with any name using `func` but in this case we need to name it `main` as this is where the code starts.
関数は `func` を使って任意の名前で宣言することができますが、今回はコードが始まる場所なので `main` という名前をつける必要があります。
![](Images/Day9_Go4.png)
Next we are going to look at line 3 of our code, the import, this basically means you want to bring in another package to your main program. fmt is a standard package being used here provided by Go, this package contains the `Println()`function and because we have imported this we can use this in line 6. There are a number of standard packages you can include in your program and leverage or reuse them in your code saving you the hassle of having to write from scratch. [Go Standard Library](https://pkg.go.dev/std)
次にコードの3行目を見てみましょう。これは基本的に、メインプログラムに別のパッケージを取り込むことを意味します。
fmtはGoが提供する標準パッケージで、このパッケージには `Println()` 関数が含まれており、これをインポートしたことで6行目でこれを使うことができるようになりました。 標準的なパッケージが多数用意されており、それらをプログラムに組み込んで活用したり、再利用することで、ゼロから書く手間を省くことができます。[Go標準ライブラリ](https://pkg.go.dev/std)
![](Images/Day9_Go5.png)
the `Println()` that we have here is a way in which to write to a standard output to the terminal where ever the executuable has been executed succesfully. Feel free to change the message in between the ().
ここにある `Println()` は、実行ファイルが正常に実行されたときに、その端末の標準出力に書き出す方法です。()の間のメッセージは自由に変更してください。
![](Images/Day9_Go6.png)
### TLDR
- **Line 1** = This file will be in the package called `main` and this needs to be called `main` because includes the entry point of the program.
- **Line 3** = For us to use the `Println()` we have to import the fmt package to use this on line 6.
- **Line 5** = The actual starting point, its the `main` function.
- **Line 6** = This will let us print "Hello #90DaysOfDevOps" on our system.
- 1行目** = このファイルは `main` というパッケージの中にあり、プログラムのエントリポイントを含むので `main` という名前にする必要があります。
- 3行目** = `Println()` を使用するために、6行目で fmt パッケージをインポートする必要があります。
- 5行目** = 実際のスタート地点、`main`関数です。
- 6行目** = "Hello #90DaysOfDevOps" と表示させることができます。
## 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)
@ -75,4 +78,4 @@ the `Println()` that we have here is a way in which to write to a standard outpu
- [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 10](day10.md).
[10日目](day10.md)にお会いしましょう。

View File

@ -1,36 +1,38 @@
---
title: '#90DaysOfDevOps - Variables & Constants in Go - Day 11'
title: '#90DaysOfDevOps - 変数、定数、データ型 - 11日目'
published: false
description: 90DaysOfDevOps - Variables & Constants in Go
description: 90DaysOfDevOps - 変数、定数、データ型
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048862
---
Before we get into the topics for today I want to give a massive shout out to [Techworld with Nana](https://www.youtube.com/watch?v=yyUHQIec83I) and this fantastic concise journey through the fundamentals of Go.
今日のトピックに入る前に、[Techworld with Nana](https://www.youtube.com/watch?v=yyUHQIec83I) とGoの基礎についての素晴らしい簡潔な旅に大きな賛辞を送りたいと思います。
On [Day8](day08.md) we set our environment up, on [Day9](day09.md) we walked through the Hello #90DaysOfDevOps code and on [Day10](day10.md)) we looked at our Go workspace and went a little deeper into compiling and running the code.
[Day8](day08.md)では環境を設定し、[Day9](day09.md)ではHello #90DaysOfDevOpsコードを歩き、[Day10](day10.md)ではGoワークスペースをみて、コードのコンパイルと実行について少し深く掘り下げて説明しました。
Today we are going to take a look into Variables, Constants and Data Types whilst writing a new program.
今日は、新しいプログラムを書きながら、変数、定数、データ型について見ていきます。
## Variables & Constants in Go
Let's start by planning our application, I think it would be a good idea to work on a program that tells us how many days we have remained in our #90DaysOfDevOps challenge.
## 変数、定数、データ型
The first thing to consider here is that as we are building our app and we are welcoming our attendees and we are giving the user feedback on the number of days they have completed we might use the term #90DaysOfDevOps many times throughout the program. This is a great use case to make #90DaysOfDevOps a variable within our program.
まず、アプリケーションの企画から始めましょう。#90DaysOfDevOpsチャレンジの残り日数を教えてくれるプログラムに取り組むのは良い考えだと思います。
- Variables are used to store values.
- Like a little box with our saved information or values.
- We can then use this variable across the program which also benefits that if this challenge or variable changes then we only have to change this in one place. Meaning we could translate this to other challenges we have in the community by just changing that one variable value.
ここで最初に考えるべきことは、私たちがアプリを作り、参加者を迎え入れ、完了した日数についてユーザーにフィードバックしているときに、プログラムを通して何度も#90DaysOfDevOpsという言葉を使うかもしれない、ということです。これは、#90DaysOfDevOpsをプログラム内の変数にするのに最適なユースケースです。
To declare this in our Go Program we define a value by using a **keyword** for variables. This will live within our `func main` block of code that you will see later. You can find more about [Keywords](https://go.dev/ref/spec#Keywords)here.
- 変数は、値を保存するために使用されます。
- 保存した情報や値を入れた小さな箱のようなものです。
- この変数は、プログラム全体で使用することができ、この課題や変数が変更された場合、1か所だけ変更すればよいという利点もあります。つまり、この変数の値を1つ変えるだけで、コミュニティ内の他の課題にも転用できるのです。
Remember to make sure that your variable names are descriptive. If you declare a variable you must use it or you will get an error, this is to avoid possible dead code, code that is never used. This is the same for packages not used.
Goプログラムでこれを宣言するには、変数のための**キーワード**を使用して値を定義します。これは後ほど紹介する `func main` というコードのブロックの中で使われます。[キーワード](https://go.dev/ref/spec#Keywords)については、こちらで詳しく説明しています。
変数名は説明的であることを忘れないようにしましょう。これはデッドコード(使われないコード)の可能性を避けるためです。これはデッドコード、つまり使われないコードを避けるためです。
```
var challenge = "#90DaysOfDevOps"
```
With the above set and used as we will see in the next code snippet you can see from the output below that we have used a variable.
上記のように設定し、次のコードスニペットで見るように使用すると、以下の出力から、変数を使用したことがわかります。
```
package main
@ -42,15 +44,15 @@ func main() {
fmt.Println("Welcome to", challenge "")
}
```
You can find the above code snippet in [day11_example1.go](Go/day11_example1.go)
You will then see from the below that we built our code with the above example and we got the output shown below.
上記のコードスニペットは [day11_example1.go](Go/day11_example1.go) で見ることができます。
上記の例でコードをビルドすると、以下のような出力が得られることがわかります。
![](Images/Day11_Go1.png)
We also know that our challenge is 90 days at least for this challenge, but next, maybe it's 100 so we want to define a variable to help us here as well. However, for our program, we want to define this as a constant. Constants are like variables, except that their value cannot be changed within code (we can still create a new app later on down the line with this code and change this constant but this 90 will not change whilst we are running our application)
また、今回のチャレンジは少なくとも90日ですが、次は100日かもしれませんので、ここでも変数を定義しておきたいと思います。しかし、このプログラムでは、これを定数として定義したいと思います。定数は変数のようなものですが、その値はコードの中では変更できませんこのコードで後で新しいアプリケーションを作り、この定数を変更することはできますが、アプリケーションを実行している間はこの90は変更されません
Adding the `const` to our code and adding another line of code to print this.
コードに `const` を追加し、これを表示するコードをもう一行追加してください。
```
package main
@ -65,15 +67,15 @@ func main() {
fmt.Println("This is a", daystotal, "challenge")
}
```
You can find the above code snippet in [day11_example2.go](Go/day11_example2.go)
上記のコードは [day11_example2.go] (Go/day11_example2.go) で見ることができます。
If we then go through that `go build` process again and run you will see below the outcome.
この `go build` プロセスをもう一度実行してみると、以下のような結果になります。
![](Images/Day11_Go2.png)
Finally, and this won't be the end of our program we will come back to this in [Day12](day12.md) to add more functionality. We now want to add another variable for the number of days we have completed the challenge.
最後に、これでプログラムが終わるわけではありませんが、[Day12](day12.md)でさらに機能を追加するために、またこの話に戻ります。ここで、チャレンジを完了した日数を表す別の変数を追加したいと思います。
Below I added `dayscomplete` variable with the number of days completed.
以下では、完了した日数を表す `dayscomplete` 変数を追加しています。
```
package main
@ -90,17 +92,17 @@ func main() {
fmt.Println("Great work")
}
```
You can find the above code snippet in [day11_example3.go](Go/day11_example3.go)
上記のコードは [day11_example3.go] (Go/day11_example3.go) で見ることができます。
Let's run through that `go build` process again or you could just use `go run`
もう一度 `go build` プロセスを実行してみましょう。あるいは `go run` でもかまいません。
![](Images/Day11_Go3.png)
Here are some other examples that I have used to make the code easier to read and edit. We have up till now been using `Println` but we can simplify this by using `Printf` by using `%v` which means we define our variables in order at the end of the line of code. we also use `\n` for a line break.
以下は、コードを読みやすく、編集しやすくするために私が使った他の例です。今までは `Println` を使っていましたが、 `%v` を使って `Printf` を使うことで、よりシンプルにすることができます。
I am using `%v` as this uses a default value but there are other options that can be found here in the [fmt package documentation](https://pkg.go.dev/fmt) you can find the code example [day11_example4.go](Go/day11_example4.go)
ここでは、`%v`をデフォルト値として使用していますが、他にもオプションがあり、[fmt package documentation](https://pkg.go.dev/fmt) に記載されています。また、コード例として [day11_example4.go](Go/day11_example4.go) を参照してください。
Variables may also be defined in a simpler format in your code. Instead of defining that it is a `var` and the `type` you can code this as follows to get the same functionality but a nice cleaner and simpler look for your code. This will only work for variables though and not constants.
変数もまた、より単純な形式で定義することができます。変数であることと、その型を定義する代わりに、次のようなコードを書くと、同じ機能を持ちながら、よりきれいでシンプルなコードになります。ただし、これは変数に対してのみ有効であり、定数に対しては有効ではありません。
```
func main() {
@ -108,53 +110,54 @@ func main() {
const daystotal = 90
```
## Data Types
In the above examples, we have not defined the type of variables, this is because we can give it a value here and Go is smart enough to know what that type is or at least can infer what it is based on the value you have stored. However, if we want a user to input this will require a specific type.
## データ型
We have used Strings and Integers in our code so far. Integers for the number of days and strings are for the name of the challenge.
上記の例では、変数の型を定義していません。これは、変数に値を与えることができ、Goは十分に賢いので、その型が何であるかを知っているか、少なくとも保存した値に基づいてそれが何であるかを推論することができるからです。しかし、ユーザーが入力する場合は、特定の型が必要です。
It is also important to note that each data type can do different things and behaves differently. For example, integers can multiply where strings do not.
これまでのコードでは、文字列と整数を使用してきました。日数にはInteger、課題の名前にはStringを使用しました。
There are four categories
また、それぞれのデータ型は異なることができ、異なる挙動をすることに注意することが重要です。例えば、整数は掛け算ができるのに、文字列はできない。
- **Basic type**: Numbers, strings, and booleans come under this category.
- **Aggregate type**: Array and structs come under this category.
- **Reference type**: Pointers, slices, maps, functions, and channels come under this category.
- **Interface type**
4つのカテゴリーがあります。
The data type is an important concept in programming. Data type specifies the size and type of variable values.
- **基本型**。数値、文字列、ブーリアンなどがこれに該当する。
- **集合型**。配列や構造体がこれに該当する。
- **参照型**。ポインタ、スライス、マップ、関数、チャネルがこれに該当する。
- インターフェース型
Go is statically typed, meaning that once a variable type is defined, it can only store data of that type.
データ型は、プログラミングにおいて重要な概念である。データ型は、変数値のサイズと型を指定します。
Go has three basic data types:
Goは静的型付けされており、一度変数の型が定義されると、その型のデータしか保存できないことを意味します。
- **bool**: represents a boolean value and is either true or false
- **Numeric**: represents integer types, floating-point values, and complex types
- **string**: represents a string value
Goには3つの基本的なデータ型があります。
I found this resource super detailed on data types [Golang by example](https://golangbyexample.com/all-data-types-in-golang-with-examples/)
- ブール**ブール値を表し、trueまたはfalseのどちらかである。
- Numeric**: 整数型、浮動小数点数型、複素数型を表す。
- 文字列**:文字列の値を表します。
I would also suggest [Techworld with Nana](https://www.youtube.com/watch?v=yyUHQIec83I&t=2023s) at this point covers in some detail a lot about the data types in Go.
データ型については、[Golang by example](https://golangbyexample.com/all-data-types-in-golang-with-examples/)という資料が超詳しいです。
If we need to define a type in our variable we can do this like so:
また、[Techworld with Nana](https://www.youtube.com/watch?v=yyUHQIec83I&t=2023s) は、Goのデータ型について詳しく説明しています。
もし、変数に型を定義する必要があれば、次のようにします。
```
var TwitterHandle string
var DaysCompleted uint
```
Because Go implies variables where a value is given we can print out those values with the following:
Goは値が与えられると変数を意味するので、次のようにすればそれらの値をプリントアウトすることができます。
```
fmt.Printf("challenge is %T, daystotal is %T, dayscomplete is %T\n", conference, daystotal, dayscomplete)
```
There are many different types of integer and float types the links above will cover off these in detail.
整数型と浮動小数点型には多くの種類がありますが、上記のリンクで詳しく説明します。
- **int** = whole numbers
- **unint** = positive whole numbers
- **floating point types** = numbers that contain a decimal component
- **int** = 整数
- **unint** = 正の整数
- **浮動小数点型** = 小数の要素を含む数
## 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)
@ -164,6 +167,6 @@ There are many different types of integer and float types the links above will c
- [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)
Next up we are going to start adding some user input functionality to our program so that we are asking how many days have been completed.
次は、このプログラムにユーザー入力機能を追加して、何日目が終了したかを尋ねるようにします。
See you on [Day 12](day12.md).
それでは、[12日目](day12.md)でお会いしましょう。

View File

@ -1,58 +1,59 @@
---
title: '#90DaysOfDevOps - Tweet your progress with our new App - Day 13'
title: '#90DaysOfDevOps - 新しいアプリで進捗をツイート - 13日目'
published: false
description: 90DaysOfDevOps - Tweet your progress with our new App
description: 90DaysOfDevOps - 新しいアプリで進捗をツイート
tags: 'devops, 90daysofdevops, learning'
cover_image: null
canonical_url: null
id: 1048865
---
## Tweet your progress with our new App
## 新しいアプリで進捗をツイート
On the final day of looking into this programming language, we have only just touched the surface here of the language but it is that start that I think we need to get interested and excited and want to dive more into it.
このプログラミング言語について調べる最終日、私たちはまだこの言語の表面に触れただけですが、このようなスタートだからこそ、私たちは興味を持ち、興奮し、もっと潜り込みたいと思うのだと思います。
Over the last few days, we have taken a small idea for an application and we have added functionality to it, in this session I want to take advantage of those packages we mentioned and create the functionality for our app to not only give you the update of your progress on screen but also send a tweet with the details of the challenge and your status.
このセッションでは、私たちが紹介したパッケージを利用して、画面上で進捗状況を確認できるだけでなく、チャレンジの詳細や状況をツイートする機能を作りたいと思います。
## Adding the ability to tweet your progress
The first thing we need to do is set up our developer API access with Twitter for this to work.
## 進捗をツイートする機能を追加する
Head to the [Twitter Developer Platform](https://developer.twitter.com) and sign in with your Twitter handle and details. Once in you should see something like the below without the app that I already have created.
まず最初に、Twitterで開発者用のAPIアクセスを設定する必要があります。
Twitter Developer Platform](https://developer.twitter.com)にアクセスし、自分のTwitterハンドル名と詳細情報を入力してサインインします。ログインすると、以下のような画面が表示されますが、すでに作成したアプリは表示されません。
![](Images/Day13_Go1.png)
From here you may also want to request elevated access, this might take some time but it was very fast for me.
ここから、昇格アクセスを要求することもできます。これは少し時間がかかるかもしれませんが、私の場合はとても早かったです。
Next, we should select Projects & Apps and create our App. Limits are depending on the account access you have, with essential you only have one app and one project and with elevated you can have 3 apps.
次に、プロジェクトとアプリを選択し、アプリを作成する必要があります。アカウントアクセスによって制限があり、essentialでは1つのアプリと1つのプロジェクトしか持てず、elevatedでは3つのアプリを持つことができます。
![](Images/Day13_Go2.png)
Give your application a name
アプリケーションに名前を付ける。
![](Images/Day13_Go3.png)
You will be then given these API tokens, it is important that you save these somewhere secure. (I have since deleted this app) We will need these later with our Go Application.
このAPIトークンを安全な場所に保存しておくことが重要です。(私はこのアプリを削除しました) これらは後でGoアプリケーションで必要になります。
![](Images/Day13_Go4.png)
Now we have our app created,(I did have to change my app name as the one in the screenshot above was already taken, these names need to be unique)
これでアプリの作成は完了です。(上のスクリーンショットの名前はすでに使われていたので、アプリ名を変更する必要がありました。)
![](Images/Day13_Go5.png)
The keys that we gathered before are known as our consumer keys and we will also need our access token and secrets. We can gather this information using the "Keys & Tokens" tab.
先ほど集めた鍵はコンシューマーキーと呼ばれ、アクセストークンとシークレットも必要です。これらの情報は、"Keys & Tokens "タブで収集することができます。
![](Images/Day13_Go6.png)
Ok, we are done in the Twitter developer portal for now. Make sure you keep your keys safe because we will need them later.
さて、Twitter開発者ポータルでの作業は一旦終了です。キーは後で必要になるので、必ず保管しておいてください。
## Go Twitter Bot
## Go ツイッターボット
Remember the code we are starting within our application as well [day13_example1](Go/day13_example1.go) but first, we need to check we have the correct code to make something tweet
アプリケーション内で開始するコードも覚えておいてください [day13_example1](Go/day13_example1.go) しかし、まず、何かをツイートするための正しいコードがあることを確認する必要があります。
We now need to think about the code to get our output or message to Twitter in the form of a tweet. We are going to be using [go-twitter](https://github.com/dghubble/go-twitter) This is a Go client library for the Twitter API.
Twitter にツイートするためのコードを考えましょう。ここでは [go-twitter](https://github.com/dghubble/go-twitter) を使用します。これはTwitter API用のGoクライアントライブラリです。
To test this before putting this into our main application, I created a new directory in our `src` folder called go-twitter-bot, issued the `go mod init github.com/michaelcade/go-twitter-bot` on the folder which then created a `go.mod` file and then we can start writing our new main.go and test this out.
メインアプリケーションに組み込む前にテストするために、`src` フォルダに go-twitter-bot という新しいディレクトリを作成し、そのフォルダに対して `go mod init github.com/michaelcade/go-twitter-bot` を実行すると `go.mod` ファイルが作成され、新しい main.go を書いてこれをテストできるようになりました。
We now need those keys, tokens and secrets we gathered from the Twitter developer portal. We are going to set these in our environment variables. This will depend on the OS you are running:
次に、Twitter開発者ポータルから集めたキー、トークン、シークレットが必要です。これらを環境変数に設定するつもりです。これは実行しているOSに依存します。
Windows
```
@ -69,11 +70,12 @@ export CONSUMER_SECRET
export ACCESS_TOKEN
export ACCESS_TOKEN_SECRET
```
At this stage, you can take a look at [day13_example2](Go/day13_example2.go) at the code but you will see here that we are using a struct to define our keys, secrets and tokens.
We then have a `func` to parse those credentials and make that connection to the Twitter API
この段階のコードは [day13_example2](Go/day13_example2.go) を見ていただくとして、ここでは構造体を使用してキー、秘密情報、トークンを定義していることがお分かりいただけると思います。
Then based on the success we will then send a tweet.
次に、これらの認証情報をパースして Twitter API に接続するための `func` を用意しています。
そして成功したら、ツイートを送信します。
```
package main
@ -152,13 +154,13 @@ func main() {
}
```
The above will either give you an error based on what is happening or it will succeed and you will have a tweet sent with the message outlined in the code.
上記は、起こっていることに基づいてエラーを出すか、成功し、コードに記載されているメッセージを含むツイートが送信されます。
## Pairing the two together - Go-Twitter-Bot + Our App
## 2つを組み合わせる - Go-Twitter-Bot当社アプリ
Now we need to merge these two in our `main.go` I am sure someone out there is screaming that there is a better way of doing this and please comment on this as you can have more than one `.go` file in a project it might make sense but this works.
この2つを `main.go` の中でマージする必要があります。きっと誰かがもっと良い方法があると叫んでいると思います。
You can see the merged codebase [day13_example3](Go/day13_example3.go) but I will also show it below.
マージされたコードベースは [day13_example3](Go/day13_example3.go) で見ることができますが、以下でも紹介しておきます。
```
package main
@ -261,26 +263,26 @@ func main() {
}
```
The outcome of this should be a tweet but if you did not supply your environment variables then you should get an error like the one below.
この結果、ツイートが表示されるはずですが、環境変数が指定されていない場合は、以下のようなエラーが表示されるはずです。
![](Images/Day13_Go7.png)
Once you have fixed that or if you choose not to authenticate with Twitter then you can use the code we finished with yesterday. The terminal output on success will look similar to this:
この問題を解決したら、あるいはTwitterで認証しないのであれば、昨日終了したコードを使用できます。成功したときの端末の出力は、以下のような感じになります。
![](Images/Day13_Go8.png)
The resulting tweet should look something like this:
出来上がったツイートはこのような感じになるはずです。
![](Images/Day13_Go9.png)
## How to compile for multiple OSs
I next want to cover the question, "How do you compile for multiple Operating Systems?" The great thing about Go is that it can easily compile for many different Operating Systems. You can get a full list by running the following command:
次に、"複数のオペレーティングシステム用にどのようにコンパイルするのか?"という質問を取り上げたいと思います。Goの素晴らしいところは、多くの異なるオペレーティングシステム用に簡単にコンパイルできることです。以下のコマンドを実行すれば、全リストが得られます。
```
go tool dist list
```
Using our `go build` commands so far is great and it will use the `GOOS` and `GOARCH` environment variables to determine the host machine and what the build should be built for. But we can also create other binaries by using the code below as an example.
これまでの `go build` コマンドの使用は素晴らしく、環境変数 `GOOS``GOARCH` を使ってホストマシンとビルドの対象を決定してくれます。しかし、以下のコードを例として、他のバイナリを作成することもできます。
```
GOARCH=amd64 GOOS=darwin go build -o ${BINARY_NAME}_0.1_darwin main.go
@ -290,11 +292,11 @@ GOARCH=arm64 GOOS=linux go build -o ${BINARY_NAME}_0.1_linux_arm64 main.go
GOARCH=arm64 GOOS=darwin go build -o ${BINARY_NAME}_0.1_darwin_arm64 main.go
```
This will then give you binaries in your directory for all of the above platforms. You can then take this and create a makefile to build these binaries whenever you add new features and functionality to your code. I have included the [makefile](Go/makefile)
これで、上記のすべてのプラットフォーム用のバイナリがディレクトリに作成されます。これを元に makefile を作成し、コードに新しい機能を追加するたびにこのバイナリをビルドするようにすればよいのです。私は、[makefile](Go/makefile)を含めています。
This is what I have used to create the releases you can now see on the [repository](https://github.com/MichaelCade/90DaysOfDevOps/releases)
これは、あなたが現在 [リポジトリ](https://github.com/MichaelCade/90DaysOfDevOps/releases)で見ることができるリリースを作成するために使用したものです。
## 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)
@ -308,8 +310,8 @@ This is what I have used to create the releases you can now see on the [reposito
- [go.dev/tour/list](https://go.dev/tour/list)
- [go.dev/learn](https://go.dev/learn/)
This wraps up the Programming language for 7 days! So much more that can be covered and I hope you have been able to continue through the content above and be able to understand some of the other aspects of the Go programming language.
これで7日間のプログラミング言語の学習は終了です。上記の内容を続けて、プログラミング言語Goの他の側面を理解することができれば幸いです。
Next, we take our focus into Linux and some of the fundamentals that we should all know there.
次は、Linuxとそこで知っておくべき基本的なことに焦点を当てます。
See you on [Day 14](day14.md).
それでは、[Day14](day14.md)でお会いしましょう。

View File

@ -26,15 +26,15 @@ English Version | [中文版本](zh_cn/README.md) | [繁體中文版本](zh_tw/R
- [✔️] ♾️ 5 > [計画 > コーディング > ビルド > テスト > リリース > デプロイ > オペレート > 監視](Days/day05.md)
- [✔️] ♾️ 6 > [DevOps - 本当の話](Days/day06.md)
### Learning a Programming Language
### プログラミング言語の学習
- [✔️] ⌨️ 7 > [The Big Picture: DevOps & Learning a Programming Language](Days/day07.md)
- [✔️] ⌨️ 7 > [全体像: DevOpsとプログラミング言語の学習](Days/day07.md)
- [✔️] ⌨️ 8 > [GoとHello WorldのためのDevOps環境のセットアップ](Days/day08.md)
- [✔️] ⌨️ 9 > [Let's explain the Hello World code](Days/day09.md)
- [✔️] ⌨️ 9 > [Hello Worldのコードを説明しましょう](Days/day09.md)
- [✔️] ⌨️ 10 > [The Go Workspace & Compiling & running code](Days/day10.md)
- [✔️] ⌨️ 11 > [Variables, Constants & Data Types](Days/day11.md)
- [✔️] ⌨️ 11 > [変数、定数、データ型](Days/day11.md)
- [✔️] ⌨️ 12 > [ポインタを使ったユーザー入力の取得と完成したプログラム](Days/day12.md)
- [✔️] ⌨️ 13 > [Tweet your progress with our new App](Days/day13.md)
- [✔️] ⌨️ 13 > [新しいアプリで進捗をツイート](Days/day13.md)
### Knowing Linux Basics