Shadowing Practice: Build a Microservice with Go #1 - Getting Started - Learn English Speaking with Video

Bir pratik modu seçin

Her mod tam ekran bir pratik odası açar.

204 cümleler
Cümleler çok kısa veya çok uzun ise, ayarlamak için Düzenle'ye tıklayın.
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

Uygulamayı İndir

Akıcı konuşmak için ihtiyacınız olan her şey

AI TelaffuzHer cümleyi puanla
IPA AlıştırmasıHer sesi ustalaştır
Kelime BilgisiKelime bankanızı oluşturun
Kelime OyunuOynarken öğrenin

Aynı Kanal

FOR YOU

Video Öner

Bu dersin kelimeleri ve konuşma notları

Bu C1 seviyesindeki konuşma dersi “Build a Microservice with Go - Getting Started” videosuna dayanıyor. En çok tekrarlanan kelimeler: add, server, http, git, command. Bu videoda gölgeleme çalışması için 204 cümle ve 3192 kelime var. Konuşma bölümü 16:16 sürüyor. Konuşmacı hızlı konuşuyor, dakikada yaklaşık 196 kelime; bu yüzden birbirine bağlanan ve zayıflayan sesler duyacaksınız. Kelimelerin %83’i İngilizcede en sık kullanılan 3.000 kelime arasında; geri kalanına başlamadan önce bakmakta fayda var.

Bu videodaki önemli kelimeler

Videodaki en ileri düzey 15 kelime, telaffuzu ve anlamıyla:

KelimeTelaffuzAnlam
router isim/ˈɹaʊ.tɚ/yönlendirici
initialize fiil/ɪˈnɪʃəlaɪz/ilklendirmek
parameter isim/pəˈɹæm.ə.tɚ/parametre
directory isim/dɪˈɹɛktəɹi/dizin, klasör
binary sıfat/ˈbaɪ.nə.ɹi/iki terimli, ikilik
conform fiil/kənˈfɔɹm/uymak
pointer isim/ˈpɔɪn.təɹ/işaret çubuğu
worthwhile sıfat/ˌwɜː(ɹ)θˈwaɪl/değer, faydalı
inbound sıfat/ˈɪnbaʊnd/gelen, gelmekte olan
localhost isimlocalhost
abstraction isim/æbˈstɹæk.ʃn̩/soyutlama, abstraksiyon
ampersand isim/ˈæm.pə(ɹ).sænd/ampersand, ve imi
artifact isim/ˈɑɹtɪfækt/artefakt, insan yapımı
compiler isim/kəmˈpaɪlɚ/derleyici
concatenate fiil/kənˈkæ.tə.neɪt/zincirleme bağlamak

Duyacağınız deyimsel fiiller

KelimeAnlam
check out fiilgözden geçirmek

Tekrar etmeye değer cümleler

Videodan, günlük konuşmada yeniden kullanabileceğiniz kısa ve tam cümleler:

  • 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.

Bu videodaki dil bilgisi

Konuşmacının en çok kullandığı yapılar, videodaki sözcüklerin aynısıyla:

YapıVideoda
Edilgen yapı be + fiilin üçüncü hâli — kimin yaptığı değil, ne olduğu önemliis installed · is specified · are organised
İlgi cümlecikleri who / which + cümle — bir kişi ya da şey hakkında ek bilgipackage, which is · servers, which is · ampersand, which means
Present perfect have/has + fiilin üçüncü hâli — geçmişte olan ama şimdi de önemli olan bir eylemI've brought · haven't noticed · We've just created

Dikkat edilecek telaffuzlar

Konuşmacı we're, we'll, I'm gibi kısaltılmış biçimleri 56 kez kullanıyor. Bunları duyduğunuz gibi kısa söyleyin.

  • “th” sesleri: worthwhile /ˌwɜː(ɹ)θˈwaɪl/, underneath /ˌʌndɚˈniθ/
  • “sh” ve “zh” sesleri: initialize /ɪˈnɪʃəlaɪz/, instantiate /ɪnˈstænʃieɪt/, abstraction /æbˈstɹæk.ʃn̩/, conventionally /kənˈvɛnʃənəli/
  • Uzun kelimeler — vurguyu doğru yere koyun: initialize /ɪˈnɪʃəlaɪz/, parameter /pəˈɹæm.ə.tɚ/, directory /dɪˈɹɛktəɹi/, dependency /dɪˈpɛndənsi/, decentralize /diːˈsɛntɹəlaɪz/

Türkçe konuşanların zorlandığı sesler:

  • /w/ — dudaklar yuvarlak, /v/ değil: worthwhile /ˌwɜː(ɹ)θˈwaɪl/, keyword /ˈkiː.wɜːd/, backward /ˈbækwɚd/
  • Kelime başındaki ünsüz kümesi — araya ünlü eklemeyin: specify /ˈspɛs.əˌfaɪ/, tutorial /ˌtjuːˈtɔːɹɪəl/, graphical /ˈɡɹæfɪkəl/, preferable /ˈpɹɛf.(ə.)ɹə.b(ə)l/, prefix /ˈpɹiːfɪks/
  • /æ/ — “e”den daha açık: handler /ˈhænd.lə/, parameter /pəˈɹæm.ə.tɚ/, advert /ædvˈɝt/, instantiate /ɪnˈstænʃieɪt/, abstraction /æbˈstɹæk.ʃn̩/

Bu videoyla nasıl çalışılır

  1. Videonun tamamını konuşmadan bir kez dinleyin ve bilmediğiniz kelimeleri not edin.
  2. 0,75× hızla başlayın, cümle cümle tekrar edin ve kolaylaşınca normal hıza dönün.
  3. Kendinizi kaydedin ve orijinaliyle karşılaştırın; router, initialize, parameter gibi kelimelere özellikle dikkat edin.

Gölgeleme Tekniği Nedir?

Gölgeleme, başlangıçta profesyonel tercüman eğitimi için geliştirilen ve çok dilli Dr. Alexander Arguelles tarafından popüler hale getirilen, bilim destekli bir dil öğrenme tekniğidir. Yöntem basit ama güçlüdür: ana dili İngilizce olan bir sesi dinler ve hemen yüksek sesle tekrar edersiniz — konuşmacıyı 1-2 saniye gecikmeyle takip eden bir gölge gibi. Pasif dinleme veya dilbilgisi alıştırmalarının aksine, gölgeleme beyninizi ve ağız kaslarınızı gerçek konuşma kalıplarını eşzamanlı olarak işlemeye ve yeniden üretmeye zorlar. Araştırmalar, telaffuz doğruluğu, tonlama, ritim, bağlı konuşma, dinleme anlama ve konuşma akıcılığını önemli ölçüde geliştirdiğini göstermektedir — bu da onu IELTS Konuşma hazırlığı ve gerçek dünya İngilizce iletişimi için en etkili yöntemlerden biri yapar.

Shadowing tekniği: adım adım eksiksiz rehberi okuyun →