How To Build A Complete JSON API In Golang (JWT, Postgres, and Docker) Part 2

Поділитися
Вставка
  • Опубліковано 5 лис 2022
  • In this series, I will teach you how to build a complete industry-ready JSON API project in Golang with JWT authentication, Postgresql, and Docker. We are going to build a bank API and build everything from scratch with only the mandatory packages we actually need. We are also going to write tests for each of our HTTP handlers. If you want to learn Golang or Rust consider subscribing to my channel so you can become a high-value engineer.
    This golang tutorial is something for you if you are willing to learn about Golang testing, Golang project structure, and how to use Docker with Golang.
    📢 I am also building a Discord community! Feel free to join if you are willing to learn about blockchain, web3, Defi, and quantitative trading. Or just hang out and chat.
    / discord
    ► Support me on PATREON and get access to exclusive lessons, tutorials, and LIVE streams
    / anthonygg_
    ► Join my Discord community for free education
    / discord
    ► Follow me on GitHub
    github.com/anthdm
    ► Follow me on Twitter
    / anthdm
    #golang #docker

КОМЕНТАРІ • 99

  • @anthonygg_
    @anthonygg_  Рік тому +5

    👉 Join the Discord community for blockchain, distributed systems, Golang, and Rust education:
    discord.gg/bDy8t4b3Rz
    👉 Support me on Patreon for even more exclusive videos, vlogs, and tutorials:
    www.patreon.com/anthonygg_
    The code can be found on GitHub: github.com/anthdm/gobank
    Thanks for watching

  • @leofreiitas
    @leofreiitas 5 місяців тому +12

    That is the best tutorial I have seen in my life, this is actually what happens and how we build applications. All tutorials that I have watched all examples were already preprogrammed, and the professor never shows how it is real process of building application. I really loved these 5 Go videos.

  • @shivamshekhar8401
    @shivamshekhar8401 Рік тому +27

    About the "_" (underscore) in imports - Generally used when you want to load a library and run its scripts without having anything to do with what it returns.
    Great series of tutorials. You are amazing!

  • @mellkam
    @mellkam Рік тому +29

    You are a very energetic teacher. Thank you for your videos 🔥

  • @programmermiskin222
    @programmermiskin222 Рік тому +10

    I love the way you teach. You keep the vibe as casual as possible that I enjoy the lesson till I finish this video. Keep it up man

  • @scalitics
    @scalitics 5 місяців тому

    In a few hours, I followed the first two videos today. I tried to take my time to fully understand and it's really incredible how much we did in two videos!
    You're a killer Anthony!

  • @MorbidPasta
    @MorbidPasta Рік тому +10

    "you are a package slave, you don't know shit"
    *googles SQL create table command*
    haha love this series, you've got a great teaching style I'm learning a lot. BTW, I've got an annie pro 60% and the backtick is FN+esc on there

  • @caiocesarmelolopes2156
    @caiocesarmelolopes2156 11 місяців тому +2

    Tip: If you create a type serial on your postgresql table, it actualy create a sequence to that column and the default value will be aways a nextval(''table_name_column_name_seq'), is really good for ID's and sequencials, but in this example for a balance, every time you insert a account if you not specify balance = 0, the balance will be the nextval of the sequence xD
    Thanks for this video btw, you are helping me alot :D

  • @sovrinfo
    @sovrinfo Рік тому +1

    Thanks Anthony. Great video!

  • @minilikshumete2430
    @minilikshumete2430 21 день тому

    Thank you 🙏.
    _ package -> the underscore following the package is for side effect only with out calling any method from it.

  • @terriprifti5069
    @terriprifti5069 Рік тому +1

    Very helpful series, great job!

  • @parthokr
    @parthokr Рік тому +4

    The problem was not with w.Header().Set() or .....Add() it was with you had to call w.WriteHeader(status) after setting content type.
    Great content. Thanks.

  • @douglashoffmann6483
    @douglashoffmann6483 Рік тому +3

    Thx for the video man, really helping to absorb the experience for my go development.
    When starting on a new language the best way to learn how to do things is to see how other people does, and not try to push my own way of thinking coming from other languages.

  • @vijeyash1
    @vijeyash1 Рік тому +3

    I can see a uniqueness in your videos. thank you for the videos.

  • @roach_jsh
    @roach_jsh 10 місяців тому

    Thank you for sharing those things! I'm not good at English, but I've finished making this project with your video!
    Actually, I don't grasp how the framework works under the hood so far. These days, I'm trying to read the framework or library code to understand how it works under the hood. Thank you, Anthony. It's a really nice lecture I've ever seen before, To learn how to make a REST API Server with Go!
    I wish that If I were good at English, I'll make the lecture like this!

  • @coscoexotic
    @coscoexotic 5 місяців тому

    great series, love the minimal use of frameworks/libraries

  • @prateek5668
    @prateek5668 7 місяців тому

    Awesome Video Anthony!!

  • @tpotjj2979
    @tpotjj2979 Рік тому +1

    Thanks again Anthony, great video!!

  • @devsbookclub
    @devsbookclub 8 місяців тому +1

    great tutorial, love the energy and style! subscribed hope you got the autocomplete fixed eventually in this series 💀

  • @ThangTran-hi3es
    @ThangTran-hi3es 7 місяців тому +1

    This man so fun, I love your videos. Thanks

  • @shomikhan1333
    @shomikhan1333 11 годин тому

    Thanks a lot......
    You are as awesome as your contents....
    Thanks again....

  • @mounis
    @mounis 8 місяців тому +1

    Great content!

  • @plashless3406
    @plashless3406 Рік тому

    You are really magic person. Thanks Anthony. I wish I could be a premium member and could buy your course.
    Anyhow, really really appreciate your efforts. I'm learning a lot.

  • @gencis44
    @gencis44 8 місяців тому +1

    Anthony is funny as hell.... "Don't be package slave , lets say the world explode and there are no packages anymore then you screwed". ... so so true
    i could not stop laughing. ..... kiakiakia kiakiakia. .... love u man

  • @rizwansworld
    @rizwansworld 2 місяці тому

    Thanks man. Impressive stuff.

  • @nodidog
    @nodidog Рік тому +1

    Thanks a lot for making this series, I've enjoyed it and it's helped reinforce some things for me (between drinking many margaritas)

  • @ibnuhazar366
    @ibnuhazar366 10 місяців тому

    I love when you made typo and say "what's going on here" 🤣
    btw thankyou so much for the tutorials!

  • @mbydokht4556
    @mbydokht4556 Рік тому +2

    Buddy i've learnt lotta things from you ty! btw, it's an interesting rule. first make it to work then make it better ultimitly make it fast.

  • @kohanokhrin
    @kohanokhrin Рік тому

    Thanks, Antony!

  • @EUU100
    @EUU100 Рік тому +1

    Thank you!

  • @kodavatiajay5762
    @kodavatiajay5762 5 місяців тому

    Get it work, make it better, then make it work faster 🙇‍♂🙇‍♂, loved the series, Thanks @Anthony

  • @victorguidi6223
    @victorguidi6223 Рік тому +2

    Yooh Anthony, amazing video and content like always!! By the way the thing ` in the 60% key board you get by using Fn + ESC, at least thats in mine a 60% US Layout and I use the USA international for the language lol
    Cheers and thank for the video!!

    • @anthonygg_
      @anthonygg_  Рік тому +2

      Wow thanks! Searching for this for a long time.

  • @PKP-vp3xq
    @PKP-vp3xq 8 місяців тому +3

    I know this is ultra noob but I'm commenting here incase somebody runs into this issue. Doing this exercise on windows and I constantly kept getting this error " pq: password authentication failed for user "postgres" ". Turns out I already had postgres (not through docker) running on port 5432 for another project and that was being accessed when I tried connecting to the docker postgres instance and hence the incorrect password.

    • @exepinero5533
      @exepinero5533 7 місяців тому

      Thank you, i forgot i got installed postgres in this machine, jesus haha

  • @martinhotmann7868
    @martinhotmann7868 Рік тому

    I actually liked it at 35:50 .. love goes out to Bobb Ross and all his fans ❤

  • @_omartariq
    @_omartariq Рік тому +2

    we are importing the postgres driver like this because we are using the api provided by golang so the package job is to register the postgres driver to the go standard sql api

  • @aleksandrpetrov3938
    @aleksandrpetrov3938 4 місяці тому

    The problem with JSON was not because of Add or Set but because of the order of the functions calls. "WriteHeader SENDS an HTTP response header with the provided status code" - description from stdlib. So by the moment you set the header application/json, response is sent as I understand

  • @caiocesarmelolopes2156
    @caiocesarmelolopes2156 11 місяців тому

    the underline is actually to tell the compiler that you are not using the lib itself, just its side effetcs, under the hood the db.Sql uses the driver to connect with the postgres, we do not explict use it on our code xD

  • @user-zx3vp8mw7d
    @user-zx3vp8mw7d Рік тому +2

    Great learning experience.
    Any non-web based projects you recommend to get confidence in golang? I am picking up some Python book and trying to solve problems in Go. Many golang books don't have exercises..

  • @AlexTitarenko87
    @AlexTitarenko87 10 місяців тому

    Fabulous

  • @justtil6749
    @justtil6749 7 місяців тому +1

    The `` symbol is located (american layout) above the tab key, below the ESC and left of the 1 key.

  • @lukaszmatuszewski
    @lukaszmatuszewski 11 місяців тому

    Now we should all get idiomatic with Postgres 🐘 Anyway your presentation style makes me want just to get down to doing things and not seek the nonexistent perfect!

  • @madebymercado5218
    @madebymercado5218 Рік тому

    For create tables, you could consider db migration.

  • @eduardabramovich1216
    @eduardabramovich1216 Рік тому +3

    That white backgroung in your postman is killing my eyes. Since i switched to dark backgrounds I'm such a crybaby.

  • @TattedFaceJoey
    @TattedFaceJoey 10 місяців тому

    The backtick (`)is supposed to be the button right of the +/= button. If it's not there, it's the button left of the !/1 key.

  • @jonathanlambrecht5642
    @jonathanlambrecht5642 9 місяців тому +1

    ` should be some modifier key and esc key on 60% us layout acording to google.

  •  Рік тому +1

    Hey Anthony, for the backtick try the following combination: Alt + 96

    • @anthonygg_
      @anthonygg_  Рік тому

      Hey man. Figured the tick out 🤣 fn esc on my keyboard. Thanks though!

    • @NguyenDuy-mj3wh
      @NguyenDuy-mj3wh Рік тому

      for me, it is cmd+fn1+esc Im so scare every time I have to type this character LOL

  • @squ34ky
    @squ34ky Рік тому

    15:36 What about using a migration tool to create your database structures? I use the Soda CLI and Fizz DSL from the Gobuffalo project with great success. Migrations are easy-peasy after the initial hurdle of learning the DSL.
    Edit: _I already know how to write the queries in plain SQL, so if the objective is to learn SQL while you're also learning Go this might not be a good idea..._

  • @Nexjsdeveloper
    @Nexjsdeveloper Рік тому +1

    I didnt find out why u just used pointer for accounts,
    I saw ur video about pointers but now what is benefit of pointer recivers ? I think u can use value reciver

  • @na50r24
    @na50r24 14 днів тому

    Not sure if this will be answered later but how do you differentiate between handleGetAccount and handleGetAccountById?
    Because the thing that kind of routes the endpoints to the function is the handleAccount function and there you say: If the method is r.GET, it should return handleGetAccount. Wouldn't that mean handleGetAccountByID is never used?

  • @adhdadventure
    @adhdadventure 3 місяці тому

    Have you done a part three with the JWT stuff

  • @Punkerobmx
    @Punkerobmx 7 місяців тому

    The conventions for create apis are: methods (post, get) domain/accounts and (get, put, delete, patch) domain/accounts/{id}

  • @amardeepsingh1168
    @amardeepsingh1168 Рік тому

    Hi, quick question would it be fine to modify Server struct like port, usersStore, transactionsStore, secrets. Can we break single store in multiple beacuse if we have 20 methods on interface it will be difficult to test it ?

  • @madebymercado5218
    @madebymercado5218 Рік тому

    Great tutorial. I know it's your setup but red/pink on black is too hard to see. I hope you'll change for video/user-friendly screen. Thanks!

  • @blazinglyfaster9935
    @blazinglyfaster9935 Рік тому +2

    it's time to put an end to package slavery!

  • @elvisosuji2707
    @elvisosuji2707 Рік тому

    Hello Anthony, Please how can i fix my response form text to jSON ? how did you fix it, you didnt tell us in the tutorial

  • @CallousCoder
    @CallousCoder 4 місяці тому

    Isn't there a difference between new(Account) and &Account that the &account is a pointer on the stack? and new on the heap?
    That's a difference in C/C++ anyways and you may the be referencing a pointer that went out of scope. So I would opt for new from my C++ background. Or use & only for objects that are created in pain and pass around that pointer.

  • @notnull01
    @notnull01 Рік тому +1

    Looks like gorilla mux has been archived, will you be doing a new series on a new mux?

  • @dredogu06
    @dredogu06 Рік тому

    Thanks Anthony

  • @amardeepsingh1168
    @amardeepsingh1168 Рік тому

    Can we use fmt.SprintF() instead of `` ?

  • @TDmitry412
    @TDmitry412 4 місяці тому

    This programming language is a struct hell )

  • @stefanovillata9658
    @stefanovillata9658 10 місяців тому +1

    I don't understand a thing, why did you incapsulated db into PostgresStore type? The entire project would have worked anyway using directly db, no?

    • @anthonygg_
      @anthonygg_  10 місяців тому +1

      Not sure what you mean. But its probably for interface stuff later on. So you can also have a mongodb store. Something like that

    • @stefanovillata9658
      @stefanovillata9658 10 місяців тому

      @@anthonygg_ I was talking about the struct PostgresStore, btw yes understood thank you. Creating that struct you can gracefully handle the db connection in the NewPostgressStore func, and then of course you will be able to have several different stores such as MongoStore. Btw I really appreciate your coding style (even though i'm still learning) and your teaching style!

  • @hakimchulan
    @hakimchulan Рік тому

    How do you tab all the lines above at 23:51

  • @foreveryoung6108
    @foreveryoung6108 Рік тому +2

    Why you use lib/pq? This library is deprecated and now jackc/pgx is prefer.

  • @amoyou943
    @amoyou943 7 місяців тому +1

    this is save foor sql injection !!!!

  • @TheSupahG
    @TheSupahG Рік тому +1

    when doing rows.next() dont forget to add rows.Close()!!!

    • @anthonygg_
      @anthonygg_  Рік тому

      Dayum, true true. Thanks for reminding me

  • @eduardabramovich1216
    @eduardabramovich1216 Рік тому

    May I ask why you name all your packages as "main"? Isn't it more easy to understand code and maintain it using different package names so that you can know which code comes from those? Just learning the lang.

    • @whimahwhe
      @whimahwhe 10 місяців тому

      he talks about it in the first part, I would add that it's far easier to split in modules once you have a good idea of the parts that your application is gonna involve, not before

  • @johnmishell234
    @johnmishell234 2 місяці тому

    For me the ` symbol is right alt and escape

  • @hakimchulan
    @hakimchulan Рік тому +2

    For the blind homies T_T

  • @trullin9326
    @trullin9326 4 місяці тому

    Never actually showed how to get the new ID out of the database, or return the newly created account via the API. Feels like you lost heart in this. Shame

  • @gimtwi
    @gimtwi 10 місяців тому

    you're so funny man, such a joy learning from you

  • @domenicwalther2479
    @domenicwalther2479 4 місяці тому

    Love the stuff your teaching, but damn it's unbearable watching you. Just spamming keyboard to look fast, making more typos than actually right ones, like slow down man..

  • @georgelza
    @georgelza Рік тому

    working through your examples, but having a problem with packages in different files, my normal structure...
    go.mod
    go.sum
    main.go
    I normally dump all code into main.go, but I'd like to maybe create a api packages and a types package and utils package
    As I understand that would mean a api, types and utils sub directory under cmd and I then do import of "api" "types" and "utils"
    issue, when done like this then the code in main.go that's trying to call the func's in api, types and utils errs out saying it can't find...
    please helpppp

    • @anthonygg_
      @anthonygg_  Рік тому

      Keep it simple and dont use folders.

    • @georgelza
      @georgelza Рік тому

      @@anthonygg_ tried that also. will try again.

    • @georgelza
      @georgelza Рік тому

      ... in the absence of folders, what do I import still the file name as the package name.

    • @georgelza
      @georgelza Рік тому

      @@anthonygg_ ... moved to same directory, left them as package main.
      tried importing the filename but as soon as I save it's removed by vscode ?

    • @anthonygg_
      @anthonygg_  Рік тому

      @@georgelza if in same package just call them by name without prefix