Complete Backend API in Golang (JWT, MySQL & Tests)

  Рет қаралды 51,775

Tiago

Tiago

Күн бұрын

► Checkout the channel community with exclusive courses: selfmadeengineer.com
In this course we're going to be building a production-ready E-commerce REST API in Go using JWT authentication, we'll be testing our services and connecting our server to a MySQL. We'll build everything from scratch so that I teach you just enough for you to be able to go on your own and not having to watch another video on how to build APIs in Go.
►Resources:
Source code: github.com/sikozonpc/ecom
Improvement Exercises: github.com/sikozonpc/ecom/blo...
👉 Join the private community to level up as software engineer: selfmadeengineer.com
📢 We're building a Discord community, come and join
/ discord
🙋🏼‍♂️ Socials:
X: x.com/TiagoFe01662401
Github: github.com/sikozonpc
Hope you liked and thanks for watching!
Time Stamps 👇
00:00:00 Intro
00:02:40 HTTP Server setup
00:07:00 User service
00:11:00 Database Connection & Envs
00:18:45 Registering users
00:36:07 Testing the user registration
00:47:48 Database migrations
00:56:20 User login
01:00:20 JWT Authentication
01:06:54 Products service
01:11:25 Checkout endpoint
01:27:00 Checking logged-in users
#golang #backend #api #jwtapi
Video titles ideas (for the algo):
REST API in Golang Beginner Tutorial
Building a JSON API in Golang
How to build a REST API in Golang

Пікірлер: 110
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
I've added the improvement exercises in the description. If you have any questions feel free to leave them in discord as well! Thanks for watching
@gokulakrishnanr8414
@gokulakrishnanr8414 3 ай бұрын
Something went wrong. Please try again or refresh the commment.
@Andika-hk6rd
@Andika-hk6rd 3 ай бұрын
I'm new to programming languages and I chose Go as my first language. I follow many KZbin channels, but yours is just underrated.
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Your too kind, ty! Feel free to join the Discord community if you ever have any question!
@WildLifeBackyardCamera
@WildLifeBackyardCamera Ай бұрын
been through so many tutorials that were not giving correct folder structure and finally, finally someone that do it right, thanks a lot
@mcdaddy1334
@mcdaddy1334 3 ай бұрын
I found your channel a couple of days ago and you are covering everything I wanted to see from a Go tutorial. Thank you !
@coffeeintocode
@coffeeintocode 3 ай бұрын
Great! Really enjoyed the testing approach
@cesarpeixoto7026
@cesarpeixoto7026 3 ай бұрын
really good quality and balance of explanation/time! keep up
@dabbabielkamel3434
@dabbabielkamel3434 3 ай бұрын
Thank you tiago❤
@mateuszzajac9127
@mateuszzajac9127 3 ай бұрын
great tutorial, big thanks!
@heesoolee1850
@heesoolee1850 3 ай бұрын
Amaizing video~~ thank you so much
@programmertelo
@programmertelo 3 ай бұрын
insighful . thanks Tiago
@langqin
@langqin 2 ай бұрын
very helpful!
@klaudiuszbiegacz3519
@klaudiuszbiegacz3519 3 ай бұрын
Even before watching I'm sure it's gonna be some quality content, and just when I've been looking for something like this, thanks man again!!:)
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Thank you so much 💪
@sachinbasnet8258
@sachinbasnet8258 3 ай бұрын
thanks tiago
@rostyslav5334
@rostyslav5334 3 ай бұрын
GOAT, thank you That what I was looking for some solid foundations
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
💪
@sajin.notfound
@sajin.notfound 3 ай бұрын
Great content...
@loudcoringa5935
@loudcoringa5935 14 күн бұрын
Thank so much for the video bro! I'm migrating from TypeScript and i found your video!
@prakashupadhyay9824
@prakashupadhyay9824 2 ай бұрын
this is everything a developer can ask for, I can't thank you enough man. Great content!
@TiagoTaquelim
@TiagoTaquelim 2 ай бұрын
Im glad you liked it! Thank you so much
@cristophermoreno2290
@cristophermoreno2290 3 ай бұрын
🔥 THIS IS AMAZING !! THANK YOU SO MUCH SIR
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
You're amazing 🔥
@iamfrancisco
@iamfrancisco Ай бұрын
This is such an underrated channel! Obrigado Tiago for creating these videos with such care and high quality
@TiagoTaquelim
@TiagoTaquelim Ай бұрын
Thank you so much!
@prashlovessamosa
@prashlovessamosa 3 ай бұрын
Thanks Tiago
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
💪
@fathan1247
@fathan1247 3 ай бұрын
this is what i am looking for, thankyou Tiago for making this tutorial, edited: i am glad if u can make grpc golang tutorial for the next upcoming video
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Thanks a good idea! Thank you!
@verygood5788
@verygood5788 27 күн бұрын
Cool tutorial thanks man, i went from js and py 60-70% of inforamtion the same but new concepts to hard for understand,you helped me, from me like subscription and comment ✌✌✌✌
@lazaromanuelcunga6195
@lazaromanuelcunga6195 3 ай бұрын
First of all, I really liked your channel. How about bringing a video about the complete Graphql API?
@bijayaprasadkuikel5162
@bijayaprasadkuikel5162 20 күн бұрын
I enjoyed your video. Please keep up the good work and continue making more videos.
@TiagoTaquelim
@TiagoTaquelim 20 күн бұрын
I will! Next one is scheduled for next week!
@go_lang_thang
@go_lang_thang 3 ай бұрын
nice course bro ơiiiiiiiiiiiiiiii
@arturfil
@arturfil 3 ай бұрын
Amazing video, really great content and great project setup!
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Thank you!
@arturfil
@arturfil 3 ай бұрын
@@TiagoTaquelim By the way, I've been looking into books to have more knowledge about production go project setup. Do you have any recommendations?
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
@@arturfil It's hard to say because there is no "one project setup". But check the O'Relly books on Go, they have a bunch
@arturfil
@arturfil 3 ай бұрын
@@TiagoTaquelim Will definitely have a look thank you for the suggestion
@abdullahzahid749
@abdullahzahid749 Ай бұрын
finally i find some good resources in go lang
@GreyWinds
@GreyWinds 2 ай бұрын
Great video! In another video, could you also show the connection to the docker container running the mysql server.
@youranonymousyoutuber4051
@youranonymousyoutuber4051 3 ай бұрын
I sub
@pedrolemos3030
@pedrolemos3030 3 ай бұрын
Hi, amazing video, Tiago! Really! I've learned a lot. If I could suggest an idea for a upcoming video: building a rest api using only the standard lib. I am not sure if this is a good idea, but since the 1.22 version added better routing, I would be really interested in seeing how you would make it. Thanks for the great content!
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Thank you! I'm glad you learnt a lot! Nice idea, I'll think about it! But definitely a 1.22 routing video is coming.
@norbertocammayo2334
@norbertocammayo2334 3 ай бұрын
Can you also please teach us how to integrate this with swagger ui? Thank you for sharing your knowledge.
@CodeWithRivandra
@CodeWithRivandra 2 ай бұрын
Great video dude. Anyway i want to ask one thing. Is ther other way to map sql columns to a struct in a way that more humane. It's kinda suck to do it based on order alone
@edupsousa
@edupsousa 2 ай бұрын
Great video! I would suggest avoiding editing code at the bottom of the screen as it can be hard to read with subtitles on or when the video controls are active. You can easily address this by setting the 'editor.cursorSurroundingLines' to a higher number in the VSCode configuration.
@TiagoTaquelim
@TiagoTaquelim 2 ай бұрын
Thank you so much! I'll check it out! Thanks for the advice!
@mrduongtien
@mrduongtien 7 күн бұрын
Great video, thanks man. I wanted to ask what extensions you are using for suggesting the libraries you import.
@TiagoTaquelim
@TiagoTaquelim 7 күн бұрын
Thank you! If you mean the auto completed text it's github copilot. If you mean the dialog that shows and I import it then right click on the name, it's not an extension.
@sval4020
@sval4020 Ай бұрын
Hi, Tiago, great video! Keep up rocking man! Love your content! A question I have, what is the best way to secure Go + HTMX + Echo + templ application? Are JWTs preferable or is there a different approach we should take?
@TiagoTaquelim
@TiagoTaquelim Ай бұрын
Thanks! JWTs are a good way to store the users session in the browsers independently of your tech stack, so yes.
@runners4tme
@runners4tme 3 ай бұрын
Create order should have a transaction for checking products
@aunjaffery31
@aunjaffery31 3 ай бұрын
How to map nested one-to-many join into struct? Awesome video. But please cover this part.
@98832230
@98832230 2 ай бұрын
try gorm , it is pretty easy for most of db operations.
@hectorcast943
@hectorcast943 28 күн бұрын
How would you deal with transaction between multiple store in repository pattern?
@de-is
@de-is 3 ай бұрын
Thanks for the great tutorial! Which framework/language or some core "tutorial" inspired you to use such Directory Structure for this application, directory per service? From one side it seemed like an overkill for me, but obviously, on the other side, it is a good strict organizational pattern. I as a Go beginner, saw bigger tutorials which still use simpler structure, and I in general tend to use simpler organization - but I really would like to know more about your "Application Structure Organization Pattern"
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Thank you so much! Ye, I have another video where I use a very simple structure without folder even. I still think this one is simple tho. Now, I don't follow any specific pattern, other than I split the code into "domains" where each domain is a small service. I feel this is more natural to do in Go because of the packages and the nature of the project (a REST API) however I've seen a lot of OSS using something like this.
@de-is
@de-is 3 ай бұрын
Why constructors NewAPIServer, NewStore, NewHandler, return pointers and not values. In the most cases, we are not changing these control structs fields values after they are setup, right?
@nickshilov9929
@nickshilov9929 Ай бұрын
Hey Tiago, thanks for the video! I wonder why you've decided to put all env vars to configs and not to call'em through os package? Thanks in advance for your reply!
@TiagoTaquelim
@TiagoTaquelim Ай бұрын
Hey thanks! I did consume the env vars through the os package but I've organize them into a configuration file for ease of use.
@abimanyudamarjati1936
@abimanyudamarjati1936 3 ай бұрын
great video! btw, what vscode theme did you use?
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Thanks! It's called Gruvbox.
@mrfli24
@mrfli24 29 күн бұрын
Thank God. He used standard database/sql interface, not ORM. Which vsc theme he used in the video ?
@TiagoTaquelim
@TiagoTaquelim 29 күн бұрын
It's called Gruvbox.
@OnceUponKid
@OnceUponKid Ай бұрын
i still don't know how to apply JWT for every routes as a middleware?
@sebastianletelier7947
@sebastianletelier7947 29 күн бұрын
Would love it using net/http 1.22 handlers😅
@weiSane
@weiSane Ай бұрын
Tiago this is good stuff. Thanks for this in-depth tutorial man. However, those are way too many dependencies wtf. Why not have fewer files it’s easier to maintain and easier to follow and read the code.
@TiagoTaquelim
@TiagoTaquelim Ай бұрын
Thanks! I've make a previous full length video like this before where I did not even create a folder to solely focus on teaching. However folk wanted a better starting point for bigger applications and that is why I've divided into folders here. so it can grow. Also, the project has 5 external dependencies, some of which are for security and loading the env vars, none of them is extraneous.
@weiSane
@weiSane Ай бұрын
@@TiagoTaquelimI understand given the context you have provided.
@yakomisar
@yakomisar 3 ай бұрын
Tiago, what is gruvbox plugin do you use?
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Gruvbox hard theme for vs code.
@yakomisar
@yakomisar 3 ай бұрын
By Tom Philbin ? There are more than one gruvbox theme plugin.
@aleksandrpetrov3938
@aleksandrpetrov3938 3 ай бұрын
Why do you use gorilla/mux? What do you think of the router golang 1.22 has inside already?
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
I'm still using gorilla on the videos because most people are still not using Go 1.12. Otherwise I would not use it unless necessary.
@aleksandrpetrov3938
@aleksandrpetrov3938 3 ай бұрын
@@TiagoTaquelim what would you use then? Chi or just built-in router? How can we implement middleware with built-in router? is it going to be function wrapper on a handler which I put around handler in every route description? Or we can do smth more elegant same with chi.Use ?
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
​@@aleksandrpetrov3938Hmm I would start without any dependencies, and if I needed them for example for that use-case you described then I would consider adding.
@juanjofre4807
@juanjofre4807 22 күн бұрын
Hello Tiago, hope you're doing well. I was following along this amazing tutorial and couldn't wrap my head around why in the dependency injection part, right around 31:50, its ok to pass a user.Store to a types.UserStore. one is a type and the other is an interface. why does this works? also, why you said that it didn't need to be a pointer? Thank you very much this is a super helpful video.
@TiagoTaquelim
@TiagoTaquelim 22 күн бұрын
Hey! Because that struct implements that interface, any other struct that would implement it would work there, that's why it's useful to interchange dependencies & that's how interfaces work in Go. I would recommend you to checkout more about them.
@juanjofre4807
@juanjofre4807 21 күн бұрын
@@TiagoTaquelim Amazing! thanks for the explanation. Also in the "WithJWT" utils that parses the auth token, what is the reason for passing the user store as a value and not as a pointer? given that the store is modeled as a singleton why you pass a copy of it to access its methods and not a pointer? Thanks!
@TiagoTaquelim
@TiagoTaquelim 21 күн бұрын
​@@juanjofre4807 If the user store is not an interface (i dont recall) it was probably a mistake from part.
@SushantShekhar-my7eu
@SushantShekhar-my7eu 8 күн бұрын
16:40 how do you handle your envs if not by .env files?
@TiagoTaquelim
@TiagoTaquelim 7 күн бұрын
Loading them using a CLI tool called Direnv
@kavindugunasekara448
@kavindugunasekara448 3 ай бұрын
is this microservice project?
@shaikwaris4131
@shaikwaris4131 17 күн бұрын
your vscode extensions please
@dwskme
@dwskme 3 ай бұрын
In testing user registration I don't understand, are we checking if user payload is valid or invalid? Kinda confused me. little explanation anyone.
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
We're checking if it's invalid. I did make the test fail in purpose to show you how changing the code affected the result of the test.
@muhammadyafialhakim1813
@muhammadyafialhakim1813 2 ай бұрын
which version of golang do you use in this tutorial? try to match with you so i didn't get any unnecessary errors
@TiagoTaquelim
@TiagoTaquelim 2 ай бұрын
Hey! The source code is in the description. You can get the exact version and code there.
@muhammadyafialhakim1813
@muhammadyafialhakim1813 2 ай бұрын
@@TiagoTaquelim thank you!
@codedusting
@codedusting Ай бұрын
What to do if I want to replace the mux router with the new 1.22 http router? How to create subrouter and other stuffs?
@TiagoTaquelim
@TiagoTaquelim Ай бұрын
I have a video on my channel about it.
@codedusting
@codedusting Ай бұрын
@@TiagoTaquelim before this video or afterwards?
@codedusting
@codedusting Ай бұрын
@@TiagoTaquelim found it
@codedusting
@codedusting Ай бұрын
@@TiagoTaquelim thanks
@kevinmathew8372
@kevinmathew8372 Ай бұрын
04:10 Would it better not to include ' db' in the APIServer struct?
@doooom911
@doooom911 Ай бұрын
why?
@afolayanademola461
@afolayanademola461 3 ай бұрын
hi thiago, pls how did you get sql downloaded on your mac. is it free?
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Yes it's free. There are 2 ways: you can download the MySQL Community server. Or you can use it with docker, which is how I'm doing. If you're not familiar with docker, use the first option.
@afolayanademola461
@afolayanademola461 3 ай бұрын
@@TiagoTaquelim I am using postgres. I hope I am still inline too.
@PPPsg116
@PPPsg116 22 күн бұрын
Is this rest api
@BeheadedKamikaze
@BeheadedKamikaze 2 ай бұрын
1:43 You mentioned you would set up a database and Dockerise the application but the video does not contain these steps
@TiagoTaquelim
@TiagoTaquelim 2 ай бұрын
The database we do. I just ran a mysql docker image on my end, its pretty simple. However I have left a docker-compose on the github repo.
@user-mz3kg4ge8u
@user-mz3kg4ge8u 3 ай бұрын
Are you portuguese or brasilian bro?
@TiagoTaquelim
@TiagoTaquelim 3 ай бұрын
Portuguese
@liezner
@liezner 6 күн бұрын
You still use gorilla mux even though its depreciated 👎🏾? Whats the point of naming your video gin gorm then
2 ай бұрын
*If someone is getting the following errors on Ubuntu: ### Error when running _make test_ # runtime/cgo _cgo_export.c:3:10: fatal error: stdlib.h: No such file or directory #include compilation terminated. SOLUTION: Just run _apt-get update && apt-get install build-essential_ ### Error when running _make migration add-user-table_ Below is the correct script to write on Makefile (remember to install the MySQL CLI on your machine) SOLUTION: @migrate create -ext sql -dir cmd/migrate/migrations $(filter-out $@,$(MAKECMDGOALS))
Go Pointers: When & How To Use Them Efficiently
14:09
Anthony GG
Рет қаралды 69 М.
When RESTful architecture isn't enough...
21:02
Dreams of Code
Рет қаралды 246 М.
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 15 МЛН
КАК ДУМАЕТЕ КТО ВЫЙГРАЕТ😂
00:29
МЯТНАЯ ФАНТА
Рет қаралды 1,8 МЛН
Vivaan  Tanya once again pranked Papa 🤣😇🤣
00:10
seema lamba
Рет қаралды 35 МЛН
How to create your Golang APIs from now on with v1.22
12:51
Master Go Programming With These Concurrency Patterns (in 40 minutes)
46:15
This Is The BEST Way To Structure Your GO Projects
11:08
Melkey
Рет қаралды 66 М.
The standard library now has all you need for advanced routing in Go.
13:52
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 760 М.
How To Structure Your Golang (API) Projects!?
20:28
Anthony GG
Рет қаралды 45 М.
*Next-door 10x Software Engineer* [FULL]
4:50
Programmers are also human
Рет қаралды 342 М.
The TRUTH About Golang Backend Frameworks
6:31
Melkey
Рет қаралды 105 М.
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 15 МЛН