쉐도잉 연습: Build a Microservice with Go #1 - Getting Started - 영상으로 영어 말하기 배우기

연습 모드 선택

각 모드는 전체 화면 연습실로 열립니다.

204 문장
문장이 너무 짧거나 길면 Edit를 눌러 조정하세요.
1
All right then gang, so in this series you're going to learn how to make a microservice with Go
2
and a framework called Qi or Kai or however else you want to pronounce it.
3
And to teach you how to do this I've brought in
4
the YouTuber Dreams of Code who's got a bunch of really nice videos about Go, Python, Rust and other subjects as well.
5
His videos are all really slick and informative so definitely check out his channel.
6
The link is down below the video.
7
Anyway without further ado So let the tutorial begin.
8
Go is a modern programming language that prides itself on being simple to use whilst remaining powerful and performant.
9
Because of this, Go is a language that is popular for building many different types of software, such as command line tools, network applications and microservices.
10
In this series, we're going to walk through building an API microservice in Go from start to finish.
11
By the end, you'll learn how to spin up a basic microservice API, which connects to a Redis database and is responsible for creating, reading, updating and deleting our data type.
12
So without further ado, let's get started.
13
Before we can begin writing code, we'll need to make sure we have Go installed on our system.
14
I'll be using macOS for the majority of this video, but it should be similar in other operating systems as well.
15
If you head on over to the Golang website, you should be able to find installation instructions for your operating system.
16
If you're okay with a basic installation, I recommend following the instructions found here.
17
For me however, I'm going to use a tool called Goenv, which allows us to manage multiple versions of Go on the same system.
18
So I'm going to show you how to get that set up.
19
To install Goenv, you can either follow the instructions on GitHub or use your operating systems package manager, if you have one of course.
20
For macOS, it's as simple as using brew install goenv.
21
Once Goenv is installed, run the following line to ensure that it loads every time your terminal starts, and then restart your terminal window.
22
You can test that everything is working okay with the following command.
23
If this doesn't work, then you may have missed a step.
24
With everything set up, we're now ready to install Go.
25
What's nice about using Goenv is that you're able to install the same version as I am in this tutorial, as it's very likely that a more recent version of Go is currently available at the time you're watching this.
26
You're probably okay to use the latest version of Go as the developers try hard to remain backwards compatible.
27
However, there's never a guarantee of that being the case.
28
So feel free to use the same version as I am in the video if the most recent one doesn't work.
29
To install Go, type in the following command.
30
This will install version 1.20.5.
31
After that, we can run the following command to set the global version of Go in Goenv.
32
Finally, you can test that everything is working correctly by running the go version command, which should print out 1.20.5.
33
Now we're ready to start building.
34
By the way, in case you haven't noticed, I pretty much use the terminal for most of my development.
35
I also use NeoVim as my editor of choice, but you may feel more comfortable using something like VS Code or another graphical editor.
36
The CLI commands that I use in this video should work the same for you, however, and so you may need to jump into the terminal at certain points.
37
First things first, we'll need a directory to store our project.
38
I'm going to create mine under projects slash orders API.
39
Feel free to choose a different directory for yourself however.
40
Once inside we now need to actually initialize our go project.
41
We can do this by running go mod init.
42
You'll need to add the project repo as the final argument.
43
This can be any git repo, such as github or gitlab.
44
Here I'm specifying my github repository.
45
Additionally this repo doesn't need to exist at this stage, you can always create it later and you can always rename this if you need to.
46
GoMod is basically Go's dependency management solution, similar to Node's npm or Ruby's gems.
47
However, unlike those systems, it's actually decentralized and works off of git, and therefore each Go project is specified by the git repo it relates to.
48
After running GoMod in it, you should see a go.mod file inside of your project.
49
If we open this up, we can actually see that this has our project repo inside of it.
50
Simple stuff.
51
Next, it's a good idea to initialize Git so
52
that we can actually have good hygiene on our project and track changes as we go through.
53
So, just run the git init command to initialize our repository.
54
After that, go ahead and add our initial commit, which should just be our GoMod.
55
Once that's done, open up your project in your editor, and let's start our first file.
56
Let's call this main.go to specify this is where the main function will live.
57
The first line you want to add is the package name, in this case it's the main package.
58
Every file in Go belongs to a package, which is how imports are organised.
59
In this case we're specifying that the main.go file lives in the main package, which tells the compiler that our code is a program and so it builds an executable.
60
Next we need to add our main function.
61
Every Go program has a main function, which acts as the main entry point to our code.
62
As is customary, let's start off by printing hello world inside of our main function.
63
To do this we first need to import another package, called fmt, or format.
64
Some others might call it phmt, but I disagree.
65
To do this we need to call the import format command just underneath our main package.
66
If you have a modern editor configured properly, imports should be automatically imported for you, but it's worthwhile us doing this manually just to see how this works.
67
Next head back to the main function and type in format.println .
68
You'll notice that this function is camelCase but the first letter is a capital.
69
Go uses this for encapsulation to specify that the function is public.
70
Now our program is complete.
71
Let's jump over to a terminal window and actually run this code.
72
We can do so by using go, run, and to the name of our file path.
73
In this case, main.go.
74
After a short period of time, you should see Hello World print to the console.
75
Perfect.
76
We've just created our first Go program.
77
Congratulations.
78
We can also build our code by using the go build command, converting it into a binary.
79
Go is pretty awesome and you can build binaries for other architectures if you like.
80
However, that's beyond the scope of this video.
81
Now that we have the basics down, let's turn it up and actually build a simple web server, which we'll use as the starting point for our API.
82
Go comes with a rich standard library and provides all we need to get a basic web server running, which we can extend later on.
83
To start, first add the net slash HTTP package to our imports.
84
This package provides functionality for creating both HTTP clients and servers, which is what we want.
85
Now we can instantiate an HTTP server using the following line in our main function.
86
This creates a basic go type of HTTP server and stores it in a variable called server.
87
You'll notice we're using an ampersand, which means we're storing this as a pointer and taking the memory address, rather than the value.
88
this type we can then define some of the properties of our server.
89
The first is the server's address, which will bind to port 3000 using the given string.
90
Next we'll need to specify a handler for our server.
91
This is an interface that will be called when our server receives a request.
92
Let's use the http handler function call and specify a function named basic handler, which we're going to create now.
93
To do so let's define a new function using the func keyword.
94
We'll call this basic handler as we suggested and specify the following parameters, which is what we need for our function to be able to conform to their HTTP handler interface.
95
The first parameter is called w and is a HTTP response writer.
96
This is an interface type that enables us to write what will eventually be our HTTP response.
97
The second type is called r and is a pointer of type HTTP request.
98
We can tell this is a pointer by the use of the asterisks.
99
This type represents the inbound HTTP request the server receives from the client.
100
Inside of the function let's go ahead and write a body response of hello world.
101
We can do this by calling the write method of the response writer.
102
This function expects a byte array so we'll need to cast our string to be one, which is done by using the syntax on screen.
103
All that remains is to actually run our server.
104
We can do this by calling the listen and serve method on our server type.
105
This method returns an error and it's good practice in Go to handle them.
106
This is done by using an if error check, which will check if the error exists, i.e. it's not nil.
107
Inside of the block we can then handle the error, which in our case we're just going to log it to stdout using the format.println method.
108
Okay, now we're able to go ahead and test out this code.
109
Let's jump over to a new terminal window.
110
We can run our app using the go run command we saw earlier.
111
Once that's done we can open up another terminal window and run a curl command to our localhost at port 3000.
112
This will send an HTTP GET request to our server.
113
And we can see we get a response of hello world which shows us our server is working as expected.
114
Very nice.
115
To stop the the server, head over to the window where we're running it and press Ctrl and C.
116
Now that we have our basic web server up, it's time to add some additional functionality to it.
117
The first thing we're going to want to do is handle HTTP routing.
118
You may have noticed but we currently only have a single handler in our project, which will handle all of the inbound requests.
119
We could do some basic routing inside of this handler, but that can be incredibly tedious to do so, and it's a challenge to properly handle things such as path parameters.
120
So whilst Go does have a robust standard library, it's worthwhile for us to use a third-party dependency at this point.
121
But which one?
122
Well, my go-to router used to be GorillaMux, which offered a great deal of functionality for very little abstraction,
123
whilst remaining true to the HTTP handler interface of the standard library.
124
However, as of the end of 2022, GorillaMux has been archived as read-only, So for future proofing our API, it's probably not the best choice.
125
There's plenty of other options out there however, but for this video I'm going to go with Qi.
126
This router is very similar to GorillaMarks and also conforms to the http interface of the standard library, so it works as a suitable replacement in my opinion.
127
To use Qi we first need to add it to our code.
128
There's a couple of ways to do this and they all involve using GoMod.
129
Before I show you these approaches, now is a good time to commit our code so we can easily roll back any changes.
130
If we run git status we can see that our API binary currently appears in the untracked files.
131
That's not ideal.
132
When using git it's a bad practice to commit any build
133
artifacts as they can add junk to a git repo pretty quickly.
134
To solve this we need to add a .gitignore.
135
Let's go ahead and create one.
136
Inside we can then specify the name of any file or folders we want git to, well, ignore.
137
Let's add the name of our binary, which is API.
138
Okay great, now if we run git status again we should see that the API is no longer available to be tracked.
139
Also because we're on macOS it's probably worthwhile to also add the .ds store files to our git ignore as well.
140
These files are created whenever you navigate to a directory using finder.
141
Rather than opening up our .git ignore file again, we can actually run the following command, which will concatenate a string into our .gitignore file.
142
Once that's done, go ahead and run the git add command to add all of the files in our directory, and then run the git commit command to store them.
143
Now we can demonstrate the two approaches for adding a dependency to our project.
144
The first approach is to use the go get command, which will download and add an entry to the go mod of our current go project, provided we're in one.
145
Let's try this by adding chi to our project.
146
To do so, type in the following command.
147
You'll notice that we're specifying the git repo of qi.
148
Remember, GoMod is decentralized, and so it uses the git repo URL as the package identifier.
149
Now if we take a look at our go.mod, we can see that an entry has been added.
150
So this is the first approach.
151
However, the second approach tends to be the one I use more often.
152
Let's reset our changes to show how we would use this use this.
153
For this approach, we just import the package into our code like we would any other.
154
Then when we want to add it to our GoMod, we just call GoMod tidy in our terminal.
155
This will tell Go to search for any packages within our project and add them to the Go.mod.
156
As you can see, Qi has now been added.
157
Also, you may have noticed that a Go.sum file now exists as well.
158
This is used to ensure consistency across package versions in case they are updated upstream.
159
It's a good idea to check in both the GoMod and the Go.sum files into our our Git repo, so we'll do this now.
160
Okay, with Qi added to our project and our code committed, let's actually use it with our HTTP server.
161
Heading back to our main function, we need to first initialise a new instance of the Qi router for use with our server.
162
We can do this by calling Qi.newRouter and assigning it to a variable called router.
163
In Go, any method prefix with the word new is conventionally a constructor.
164
Oftentimes it's preferable to use the constructor method instead of directly instantiating an instance, as they will often initialise private properties of the type.
165
With our new router created, let's go ahead and add a root for get slash hello, and we'll match it to the basic handler that we've already got defined.
166
We can do this by calling the router.get method and passing in our path as the first parameter.
167
The second parameter requires an http.handler function, which we can just set to our basic handler.
168
The last thing we need to do is add our router to the server handler.
169
What's really nice about Qi is that the router type itself conforms to the HTTP handler interface, so all we have to do here is replace our handler with our router instead.
170
With that done, we can go ahead and test our behaviour.
171
To do so, let's rerun our app using gorun on our main.go file.
172
Heading over to another terminal window, we can then run our curl command against our localhost at port 3000.
173
However this time you'll notice we get a 404 page not found response.
174
That's because we haven't set any handlers for the slash root, and she is automatically handling that for us, which is pretty neat.
175
Let's run curl again, but this time point it to our slash hello path.
176
This time we get back the expected hello world response.
177
There's one last thing for us to test.
178
Let's try this with a POST request instead of a GET request.
179
We can do this with curl using the X flag, which allows us to specify the HTTP method.
180
Make sure you set X to uppercase.
181
We'll also add the lowercase v flag so that we're able to see the full HTTP headers.
182
Here you can see we're getting an HTTP status response of 405, which stands for Method Not Allowed.
183
This is because we only specified a route for the method of GET in our path, and therefore Qi provides this error for us.
184
With a basic router added, it's clear we're missing something.
185
And that something is logging.
186
Qi fortunately provides us a logging middleware that we're able to use right out of the box.
187
We can add this to our router by first importing the middleware package from the Qi plugin by using the following line.
188
With our middleware imported we can then add it to the router via the use method.
189
Now if we restart our server, we should start to see logs appear whenever we handle a request and response.
190
Nice.
191
Now that we're in a good spot, it's time to commit our code again.
192
To do so, go ahead and run the git add command to stage our changes, and then type in the git commit command to go ahead and commit them.
193
By the way, the M flag stands for message, in case you hadn't guessed that already.
194
This allows us to specify the message we want to store along with our actual commit.
195
By the way, if you want to watch this entire course now without YouTube adverts, you can do.
196
It's all up on the NetNinja website, netninja.dev.
197
You can buy the course for $2 to get instant access to all of it, or you can sign up to NetNinja Pro and get instant access to all of my courses without adverts,
198
as well as premium courses not found on YouTube including my Udemy ones that's nine dollars a month
199
and you can get your first month half price
200
when you use this promo code right here
201
so I'm going to leave this link down below in the video description for you to sign up
202
and I really hope you enjoy this series
203
and please do not forget to share subscribe and like the videos
204
that really helps a lot and I'm going to see you in the very next lesson

앱 다운로드

유창하게 말하는 데 필요한 모든 것

AI 발음 평가문장마다 점수 확인
IPA 발음 연습모든 소리 마스터
단어 학습나만의 단어장 만들기
단어 게임놀면서 외우기

같은 채널

FOR YOU

추천 영상

이 레슨의 어휘와 말하기 포인트

이 C1 수준 말하기 레슨은 영상 “Build a Microservice with Go - Getting Started”을(를) 바탕으로 합니다. 가장 자주 반복되는 단어는 다음과 같습니다: add, server, http, git, command. 이 영상에는 섀도잉할 문장 204개와 단어 3192개가 있습니다. 말하는 구간의 길이는 16:16입니다. 화자는 분당 약 196단어로 빠르게 말하므로 연음과 약하게 발음되는 소리가 많습니다. 단어의 83%가 영어에서 가장 많이 쓰이는 3,000단어에 속합니다. 나머지는 연습 전에 미리 확인해 두세요.

이 영상의 핵심 어휘

영상에서 가장 어려운 단어 15개를 발음, 뜻과 함께 정리했습니다.

단어발음뜻
router 명사/ˈɹaʊ.tɚ/라우터
parameter 명사/pəˈɹæm.ə.tɚ/파라미터, 매개변수
curl 명사/kɜɹl/곱슬머리
directory 명사/dɪˈɹɛktəɹi/디렉토리, 폴더
binary 형용사/ˈbaɪ.nə.ɹi/참거짓, 진리
pointer 명사/ˈpɔɪn.təɹ/교편
functionality 명사기능
tutorial 명사/ˌtjuːˈtɔːɹɪəl/지도, 지침
artifact 명사/ˈɑɹtɪfækt/인공물
compiler 명사/kəmˈpaɪlɚ/컴파일러
configure 동사/kənˈfɪɡə(ɹ)/설정하다
keyword 명사/ˈkiː.wɜːd/키워드, 핵심어
preferable 형용사/ˈpɹɛf.(ə.)ɹə.b(ə)l/더 좋다
prefix 명사/ˈpɹiːfɪks/접두사, 접두어
rename 동사/ɹiːˈneɪm/개명하다

따라 말해 볼 만한 문장

영상에 나오는 짧고 완결된 문장으로, 일상 대화에서 그대로 쓸 수 있습니다:

  • Here I'm specifying my github repository.
  • Let's jump over to a new terminal window.
  • Let's go ahead and create one.
  • Let's try this by adding chi to our project.
  • There's one last thing for us to test.

이 영상의 문법

화자가 가장 많이 쓰는 문형을 영상 속 실제 표현과 함께 정리했습니다.

문형영상 속 표현
수동태 be + 과거분사 — 누가 하는지보다 무슨 일이 일어나는지에 초점is installed · is specified · are organised
관계절 who / which + 절 — 사람이나 사물에 대한 추가 정보package, which is · servers, which is · ampersand, which means
현재완료 have/has + 과거분사 — 과거의 일이 지금도 관련이 있을 때I've brought · haven't noticed · We've just created

주의할 발음

화자는 we're, we'll, I'm 같은 축약형과 약화된 형태를 56번 사용합니다. 들리는 대로 짧게 발음하세요.

  • “th” 소리: worthwhile /ˌwɜː(ɹ)θˈwaɪl/, underneath /ˌʌndɚˈniθ/
  • “sh”와 “zh” 소리: initialize /ɪˈnɪʃəlaɪz/, instantiate /ɪnˈstænʃieɪt/, abstraction /æbˈstɹæk.ʃn̩/, conventionally /kənˈvɛnʃənəli/
  • 긴 단어 — 강세 위치에 주의: initialize /ɪˈnɪʃəlaɪz/, parameter /pəˈɹæm.ə.tɚ/, directory /dɪˈɹɛktəɹi/, dependency /dɪˈpɛndənsi/, decentralize /diːˈsɛntɹəlaɪz/

한국어 화자가 어려워하는 소리:

  • /f/ — ㅍ(/p/)으로 바꾸지 말고 윗니를 아랫입술에 대기: specify /ˈspɛs.əˌfaɪ/, conform /kənˈfɔɹm/, artifact /ˈɑɹtɪfækt/, configure /kənˈfɪɡə(ɹ)/, finder /ˈfaɪndəɹ/
  • /v/ — ㅂ(/b/)과 구별하기: advert /ædvˈɝt/, conventionally /kənˈvɛnʃənəli/, informative /ɪnˈfɔːmətɪv/, navigate /ˈnæv.ɪ.ɡeɪt/, archive /ˈɑɹˌkaɪv/
  • /z/ — ㅈ이 아니라 성대를 울리는 /s/: initialize /ɪˈnɪʃəlaɪz/, decentralize /diːˈsɛntɹəlaɪz/, repository /ɹɪˈpɒz.ɪ.t(ə.)ɹɪ/, oftentimes /ˈɔf.ənˌtaɪmz/

이 영상으로 연습하는 방법

  1. 먼저 말하지 않고 영상을 끝까지 듣고 모르는 단어를 적어 둡니다.
  2. 0.75배속으로 한 문장씩 섀도잉을 시작하고, 익숙해지면 보통 속도로 돌아갑니다.
  3. 자신의 목소리를 녹음해 원본과 비교하고, router, parameter, curl 같은 단어에 특히 주의합니다.

쉐도잉이란? 영어 실력을 빠르게 키우는 과학적 방법

쉐도잉(Shadowing)은 원래 전문 통역사 훈련을 위해 개발된 언어 학습 기법으로, 다언어 학자인 Dr. Alexander Arguelles에 의해 대중화된 방법입니다. 핵심 원리는 간단하지만 매우 강력합니다: 원어민의 영어를 들으면서 1~2초의 짧은 지연으로 즉시 소리 내어 따라 말하는 것——마치 '그림자(shadow)'처럼 화자를 따라가는 것입니다. 문법 공부나 수동적인 청취와 달리, 쉐도잉은 뇌와 입 근육이 동시에 실시간으로 영어를 처리하고 재현하도록 훈련합니다. 연구에 따르면 이 방법은 발음 정확도, 억양, 리듬, 연음, 청취력, 말하기 유창성을 크게 향상시킵니다. IELTS 스피킹 준비와 자연스러운 영어 소통을 원하는 분들에게 특히 효과적입니다.

섀도잉 방법: 단계별 전체 가이드 읽기 →