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

Sdílet
Vložit
  • čas přidán 25. 05. 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

Komentáře • 80

  • @TiagoTaquelim
    @TiagoTaquelim  Před 2 měsíci +13

    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 Před měsícem +1

      Something went wrong. Please try again or refresh the commment.

  • @Andika-hk6rd
    @Andika-hk6rd Před měsícem +13

    I'm new to programming languages and I chose Go as my first language. I follow many CZcams channels, but yours is just underrated.

    • @TiagoTaquelim
      @TiagoTaquelim  Před měsícem +1

      Your too kind, ty! Feel free to join the Discord community if you ever have any question!

  • @abdullahzahid749
    @abdullahzahid749 Před 2 dny +1

    finally i find some good resources in go lang

  • @mcdaddy1334
    @mcdaddy1334 Před 2 měsíci +6

    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 Před 2 měsíci +2

    Great! Really enjoyed the testing approach

  • @cesarpeixoto7026
    @cesarpeixoto7026 Před měsícem +2

    really good quality and balance of explanation/time! keep up

  • @prakashupadhyay9824
    @prakashupadhyay9824 Před měsícem +2

    this is everything a developer can ask for, I can't thank you enough man. Great content!

  • @klaudiuszbiegacz3519
    @klaudiuszbiegacz3519 Před 2 měsíci +4

    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!!:)

  • @dabbabielkamel3434
    @dabbabielkamel3434 Před 2 měsíci +2

    Thank you tiago❤

  • @heesoolee1850
    @heesoolee1850 Před měsícem +1

    Amaizing video~~ thank you so much

  • @mateuszzajac9127
    @mateuszzajac9127 Před měsícem +1

    great tutorial, big thanks!

  • @edupsousa
    @edupsousa Před 17 dny +1

    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  Před 17 dny

      Thank you so much! I'll check it out! Thanks for the advice!

  • @programmertelo
    @programmertelo Před měsícem +2

    insighful .
    thanks Tiago

  • @rostyslav5334
    @rostyslav5334 Před 2 měsíci +2

    GOAT, thank you
    That what I was looking for some solid foundations

  • @cristophermoreno2290
    @cristophermoreno2290 Před měsícem +2

    🔥 THIS IS AMAZING !! THANK YOU SO MUCH SIR

  • @pedrolemos3030
    @pedrolemos3030 Před 2 měsíci +7

    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  Před 2 měsíci +5

      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.

  • @lazaromanuelcunga6195
    @lazaromanuelcunga6195 Před měsícem +2

    First of all, I really liked your channel.
    How about bringing a video about the complete Graphql API?

  • @sachinbasnet8258
    @sachinbasnet8258 Před 2 měsíci +1

    thanks tiago

  • @arturfil
    @arturfil Před 2 měsíci +2

    Amazing video, really great content and great project setup!

    • @TiagoTaquelim
      @TiagoTaquelim  Před 2 měsíci +1

      Thank you!

    • @arturfil
      @arturfil Před 2 měsíci

      @@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  Před 2 měsíci +1

      @@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 Před 2 měsíci

      @@TiagoTaquelim Will definitely have a look thank you for the suggestion

  • @fathan1247
    @fathan1247 Před 2 měsíci +2

    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

  • @langqin
    @langqin Před měsícem

    very helpful!

  • @prashlovessamosa
    @prashlovessamosa Před 2 měsíci +3

    Thanks Tiago

  • @sajin.notfound
    @sajin.notfound Před měsícem +1

    Great content...

  • @GreyWinds
    @GreyWinds Před 21 dnem

    Great video!
    In another video, could you also show the connection to the docker container running the mysql server.

  • @go_lang_thang
    @go_lang_thang Před 2 měsíci +2

    nice course bro ơiiiiiiiiiiiiiiii

  • @CodeWithRivandra
    @CodeWithRivandra Před 17 dny

    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

  • @norbertocammayo2334
    @norbertocammayo2334 Před měsícem +1

    Can you also please teach us how to integrate this with swagger ui? Thank you for sharing your knowledge.

  • @youranonymousyoutuber4051
    @youranonymousyoutuber4051 Před 2 měsíci +2

    I sub

  • @aunjaffery31
    @aunjaffery31 Před 2 měsíci +1

    How to map nested one-to-many join into struct? Awesome video. But please cover this part.

    • @98832230
      @98832230 Před 24 dny

      try gorm , it is pretty easy for most of db operations.

  • @de-is
    @de-is Před měsícem +2

    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  Před měsícem

      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.

  • @runners4tme
    @runners4tme Před 2 měsíci

    Create order should have a transaction for checking products

  • @abimanyudamarjati1936
    @abimanyudamarjati1936 Před 2 měsíci

    great video! btw, what vscode theme did you use?

  • @OnceUponKid
    @OnceUponKid Před 4 dny

    i still don't know how to apply JWT for every routes as a middleware?

  • @de-is
    @de-is Před měsícem

    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?

  • @yakomisar
    @yakomisar Před 2 měsíci

    Tiago, what is gruvbox plugin do you use?

    • @TiagoTaquelim
      @TiagoTaquelim  Před 2 měsíci

      Gruvbox hard theme for vs code.

    • @yakomisar
      @yakomisar Před 2 měsíci

      By Tom Philbin ? There are more than one gruvbox theme plugin.

  • @aleksandrpetrov3938
    @aleksandrpetrov3938 Před 2 měsíci

    Why do you use gorilla/mux? What do you think of the router golang 1.22 has inside already?

    • @TiagoTaquelim
      @TiagoTaquelim  Před 2 měsíci

      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 Před 2 měsíci

      @@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  Před 2 měsíci

      ​@@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.

  • @kavindugunasekara448
    @kavindugunasekara448 Před 2 měsíci

    is this microservice project?

  • @muhammadyafialhakim1813
    @muhammadyafialhakim1813 Před měsícem

    which version of golang do you use in this tutorial? try to match with you so i didn't get any unnecessary errors

  • @dwskme
    @dwskme Před 2 měsíci

    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  Před 2 měsíci +1

      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.

  • @kevinmathew8372
    @kevinmathew8372 Před 6 dny

    04:10 Would it better not to include ' db' in the APIServer struct?

  • @BeheadedKamikaze
    @BeheadedKamikaze Před 26 dny

    1:43 You mentioned you would set up a database and Dockerise the application but the video does not contain these steps

    • @TiagoTaquelim
      @TiagoTaquelim  Před 25 dny

      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.

  • @afolayanademola461
    @afolayanademola461 Před měsícem

    hi thiago, pls how did you get sql downloaded on your mac. is it free?

    • @TiagoTaquelim
      @TiagoTaquelim  Před měsícem +1

      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 Před měsícem

      @@TiagoTaquelim I am using postgres. I hope I am still inline too.

  • @codedusting
    @codedusting Před 16 hodinami

    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  Před 16 hodinami

      I have a video on my channel about it.

    • @codedusting
      @codedusting Před 16 hodinami

      @@TiagoTaquelim before this video or afterwards?

    • @codedusting
      @codedusting Před 16 hodinami +1

      @@TiagoTaquelim found it

    • @codedusting
      @codedusting Před 16 hodinami

      @@TiagoTaquelim thanks

  • @user-mz3kg4ge8u
    @user-mz3kg4ge8u Před 2 měsíci

    Are you portuguese or brasilian bro?

  •  Před 9 dny +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))