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

ความคิดเห็น • 82

  • @TiagoTaquelim
    @TiagoTaquelim  2 หลายเดือนก่อน +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 หลายเดือนก่อน +1

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

  • @Andika-hk6rd
    @Andika-hk6rd หลายเดือนก่อน +13

    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.

    • @TiagoTaquelim
      @TiagoTaquelim  หลายเดือนก่อน +1

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

  • @abdullahzahid749
    @abdullahzahid749 3 วันที่ผ่านมา +1

    finally i find some good resources in go lang

  • @coffeeintocode
    @coffeeintocode 2 หลายเดือนก่อน +2

    Great! Really enjoyed the testing approach

  • @mcdaddy1334
    @mcdaddy1334 2 หลายเดือนก่อน +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 !

  • @cesarpeixoto7026
    @cesarpeixoto7026 หลายเดือนก่อน +2

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

  • @heesoolee1850
    @heesoolee1850 หลายเดือนก่อน +1

    Amaizing video~~ thank you so much

  • @klaudiuszbiegacz3519
    @klaudiuszbiegacz3519 2 หลายเดือนก่อน +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!!:)

    • @TiagoTaquelim
      @TiagoTaquelim  2 หลายเดือนก่อน

      Thank you so much 💪

  • @prakashupadhyay9824
    @prakashupadhyay9824 หลายเดือนก่อน +2

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

    • @TiagoTaquelim
      @TiagoTaquelim  หลายเดือนก่อน

      Im glad you liked it! Thank you so much

  • @mateuszzajac9127
    @mateuszzajac9127 หลายเดือนก่อน +1

    great tutorial, big thanks!

  • @dabbabielkamel3434
    @dabbabielkamel3434 2 หลายเดือนก่อน +2

    Thank you tiago❤

  • @rostyslav5334
    @rostyslav5334 2 หลายเดือนก่อน +2

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

  • @programmertelo
    @programmertelo หลายเดือนก่อน +2

    insighful .
    thanks Tiago

  • @pedrolemos3030
    @pedrolemos3030 2 หลายเดือนก่อน +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  2 หลายเดือนก่อน +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.

  • @cristophermoreno2290
    @cristophermoreno2290 หลายเดือนก่อน +2

    🔥 THIS IS AMAZING !! THANK YOU SO MUCH SIR

    • @TiagoTaquelim
      @TiagoTaquelim  หลายเดือนก่อน

      You're amazing 🔥

  • @arturfil
    @arturfil 2 หลายเดือนก่อน +2

    Amazing video, really great content and great project setup!

    • @TiagoTaquelim
      @TiagoTaquelim  2 หลายเดือนก่อน +1

      Thank you!

    • @arturfil
      @arturfil 2 หลายเดือนก่อน

      @@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  2 หลายเดือนก่อน +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 2 หลายเดือนก่อน

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

  • @lazaromanuelcunga6195
    @lazaromanuelcunga6195 2 หลายเดือนก่อน +2

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

  • @fathan1247
    @fathan1247 2 หลายเดือนก่อน +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

    • @TiagoTaquelim
      @TiagoTaquelim  2 หลายเดือนก่อน

      Thanks a good idea! Thank you!

  • @sachinbasnet8258
    @sachinbasnet8258 2 หลายเดือนก่อน +1

    thanks tiago

  • @prashlovessamosa
    @prashlovessamosa 2 หลายเดือนก่อน +3

    Thanks Tiago

  • @langqin
    @langqin หลายเดือนก่อน

    very helpful!

  • @sajin.notfound
    @sajin.notfound หลายเดือนก่อน +1

    Great content...

  • @GreyWinds
    @GreyWinds 23 วันที่ผ่านมา

    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 2 หลายเดือนก่อน +2

    nice course bro ơiiiiiiiiiiiiiiii

  • @edupsousa
    @edupsousa 19 วันที่ผ่านมา +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  19 วันที่ผ่านมา

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

  • @CodeWithRivandra
    @CodeWithRivandra 19 วันที่ผ่านมา

    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 หลายเดือนก่อน +1

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

  • @nickshilov9929
    @nickshilov9929 วันที่ผ่านมา +1

    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.

  • @aunjaffery31
    @aunjaffery31 2 หลายเดือนก่อน +1

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

    • @98832230
      @98832230 26 วันที่ผ่านมา

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

  • @runners4tme
    @runners4tme 2 หลายเดือนก่อน

    Create order should have a transaction for checking products

  • @de-is
    @de-is หลายเดือนก่อน

    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?

  • @youranonymousyoutuber4051
    @youranonymousyoutuber4051 2 หลายเดือนก่อน +2

    I sub

  • @abimanyudamarjati1936
    @abimanyudamarjati1936 2 หลายเดือนก่อน

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

    • @TiagoTaquelim
      @TiagoTaquelim  2 หลายเดือนก่อน

      Thanks! It's called Gruvbox.

  • @de-is
    @de-is 2 หลายเดือนก่อน +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  2 หลายเดือนก่อน

      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.

  • @OnceUponKid
    @OnceUponKid 6 วันที่ผ่านมา

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

  • @yakomisar
    @yakomisar 2 หลายเดือนก่อน

    Tiago, what is gruvbox plugin do you use?

    • @TiagoTaquelim
      @TiagoTaquelim  2 หลายเดือนก่อน

      Gruvbox hard theme for vs code.

    • @yakomisar
      @yakomisar 2 หลายเดือนก่อน

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

  • @kevinmathew8372
    @kevinmathew8372 8 วันที่ผ่านมา

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

    • @doooom911
      @doooom911 7 วันที่ผ่านมา

      why?

  • @aleksandrpetrov3938
    @aleksandrpetrov3938 2 หลายเดือนก่อน

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

    • @TiagoTaquelim
      @TiagoTaquelim  2 หลายเดือนก่อน

      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 2 หลายเดือนก่อน

      @@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  2 หลายเดือนก่อน

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

  • @dwskme
    @dwskme 2 หลายเดือนก่อน

    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  2 หลายเดือนก่อน +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.

  • @muhammadyafialhakim1813
    @muhammadyafialhakim1813 หลายเดือนก่อน

    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  หลายเดือนก่อน

      Hey! The source code is in the description. You can get the exact version and code there.

    • @muhammadyafialhakim1813
      @muhammadyafialhakim1813 หลายเดือนก่อน +1

      @@TiagoTaquelim thank you!

  • @kavindugunasekara448
    @kavindugunasekara448 2 หลายเดือนก่อน

    is this microservice project?

  • @BeheadedKamikaze
    @BeheadedKamikaze 27 วันที่ผ่านมา

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

    • @TiagoTaquelim
      @TiagoTaquelim  27 วันที่ผ่านมา

      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.

  • @codedusting
    @codedusting 2 วันที่ผ่านมา

    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  2 วันที่ผ่านมา

      I have a video on my channel about it.

    • @codedusting
      @codedusting 2 วันที่ผ่านมา

      @@TiagoTaquelim before this video or afterwards?

    • @codedusting
      @codedusting 2 วันที่ผ่านมา +1

      @@TiagoTaquelim found it

    • @codedusting
      @codedusting 2 วันที่ผ่านมา

      @@TiagoTaquelim thanks

  • @afolayanademola461
    @afolayanademola461 หลายเดือนก่อน

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

    • @TiagoTaquelim
      @TiagoTaquelim  หลายเดือนก่อน +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 หลายเดือนก่อน

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

  • @user-mz3kg4ge8u
    @user-mz3kg4ge8u 2 หลายเดือนก่อน

    Are you portuguese or brasilian bro?

  •  11 วันที่ผ่านมา +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))