Complete Backend API in Golang (JWT, MySQL & Tests)
ฝัง
- เผยแพร่เมื่อ 27 พ.ค. 2024
- ► Join the private community to level up as software engineer: 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
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
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
Something went wrong. Please try again or refresh the commment.
I'm new to programming languages and I chose Go as my first language. I follow many TH-cam channels, but yours is just underrated.
Your too kind, ty! Feel free to join the Discord community if you ever have any question!
finally i find some good resources in go lang
Great! Really enjoyed the testing approach
I found your channel a couple of days ago and you are covering everything I wanted to see from a Go tutorial. Thank you !
really good quality and balance of explanation/time! keep up
Amaizing video~~ thank you so much
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!!:)
Thank you so much 💪
this is everything a developer can ask for, I can't thank you enough man. Great content!
Im glad you liked it! Thank you so much
great tutorial, big thanks!
Thank you tiago❤
GOAT, thank you
That what I was looking for some solid foundations
💪
insighful .
thanks Tiago
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!
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.
🔥 THIS IS AMAZING !! THANK YOU SO MUCH SIR
You're amazing 🔥
Amazing video, really great content and great project setup!
Thank you!
@@TiagoTaquelim By the way, I've been looking into books to have more knowledge about production go project setup. Do you have any recommendations?
@@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
@@TiagoTaquelim Will definitely have a look thank you for the suggestion
First of all, I really liked your channel.
How about bringing a video about the complete Graphql API?
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
Thanks a good idea! Thank you!
thanks tiago
Thanks Tiago
💪
very helpful!
Great content...
Great video!
In another video, could you also show the connection to the docker container running the mysql server.
nice course bro ơiiiiiiiiiiiiiiii
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.
Thank you so much! I'll check it out! Thanks for the advice!
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
Can you also please teach us how to integrate this with swagger ui? Thank you for sharing your knowledge.
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!
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.
How to map nested one-to-many join into struct? Awesome video. But please cover this part.
try gorm , it is pretty easy for most of db operations.
Create order should have a transaction for checking products
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?
I sub
great video! btw, what vscode theme did you use?
Thanks! It's called Gruvbox.
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"
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.
i still don't know how to apply JWT for every routes as a middleware?
Tiago, what is gruvbox plugin do you use?
Gruvbox hard theme for vs code.
By Tom Philbin ? There are more than one gruvbox theme plugin.
04:10 Would it better not to include ' db' in the APIServer struct?
why?
Why do you use gorilla/mux? What do you think of the router golang 1.22 has inside already?
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.
@@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 ?
@@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.
In testing user registration I don't understand, are we checking if user payload is valid or invalid? Kinda confused me. little explanation anyone.
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.
which version of golang do you use in this tutorial? try to match with you so i didn't get any unnecessary errors
Hey! The source code is in the description. You can get the exact version and code there.
@@TiagoTaquelim thank you!
is this microservice project?
1:43 You mentioned you would set up a database and Dockerise the application but the video does not contain these steps
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.
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?
I have a video on my channel about it.
@@TiagoTaquelim before this video or afterwards?
@@TiagoTaquelim found it
@@TiagoTaquelim thanks
hi thiago, pls how did you get sql downloaded on your mac. is it free?
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.
@@TiagoTaquelim I am using postgres. I hope I am still inline too.
Are you portuguese or brasilian bro?
Portuguese
*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))