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

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ธ.ค. 2024

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

  • @anthonygg_
    @anthonygg_  2 ปีที่แล้ว +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

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

      Hey,
      In case you haven't found how to type ` on 60% kb, it's: fn + esc.
      The tutorial is second to none, thank you for that.

  • @leofreiitas
    @leofreiitas 10 หลายเดือนก่อน +14

    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 ปีที่แล้ว +37

    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 2 ปีที่แล้ว +31

    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

  • @unknownplayer-c1i
    @unknownplayer-c1i 10 หลายเดือนก่อน

    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!

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

    This is one of the best tutorials in GO back-end.

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

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

    I'm quite new to golang, but have programmed in a lot of languages during time, starting with pascal, C and assembler all the way back in the late 80'ties.
    I'm starting to like golang, as it reminds me a bit about the "old" stuff, but with all the annoying stuff filtered away and some of the new stuff put in instead.
    I like way you explain it, as it doesn't seem to be a rehearsed thing you did before, and just copy/paste it. That make the video more interesting, as it's more real world kind of doing it.
    That makes it more fun and not just like a bunch of overheads thrown in your face 🙂
    So, thanks for the good work :-)

  • @caiocesarmelolopes2156
    @caiocesarmelolopes2156 ปีที่แล้ว +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

  • @parthokr
    @parthokr ปีที่แล้ว +5

    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.

  • @roach_jsh
    @roach_jsh ปีที่แล้ว

    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!

  • @ThangTran-hi3es
    @ThangTran-hi3es ปีที่แล้ว +2

    This man so fun, I love your videos. Thanks

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

    great series, love the minimal use of frameworks/libraries

  • @sovrinfo
    @sovrinfo 2 ปีที่แล้ว +1

    Thanks Anthony. Great video!

  • @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)

  • @mellow-meanderings
    @mellow-meanderings ปีที่แล้ว +1

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

  • @prateek5668
    @prateek5668 ปีที่แล้ว

    Awesome Video Anthony!!

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

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

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

  • @tpotjj2979
    @tpotjj2979 2 ปีที่แล้ว +1

    Thanks again Anthony, great video!!

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

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

  • @mounis
    @mounis ปีที่แล้ว +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.

  • @_omartariq
    @_omartariq 2 ปีที่แล้ว +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

  • @MorbidPasta
    @MorbidPasta 2 ปีที่แล้ว +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

  • @terriprifti5069
    @terriprifti5069 2 ปีที่แล้ว +1

    Very helpful series, great job!

  • @martinhotmann7868
    @martinhotmann7868 ปีที่แล้ว

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

  • @victorguidi6223
    @victorguidi6223 2 ปีที่แล้ว +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 ปีที่แล้ว +2

      Wow thanks! Searching for this for a long time.

  • @gencis44
    @gencis44 ปีที่แล้ว +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

  • @justtil6749
    @justtil6749 ปีที่แล้ว +1

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

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

    the issue for the headers not being set wasn't changing it to add , the issue was we can only set the headers once , in our function , any subsequent changes aren't displayed . So moving it to the top , made it work

  • @ibnuhazar366
    @ibnuhazar366 ปีที่แล้ว

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

  • @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..._

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

    Thanks man. Impressive stuff.

  • @gimtwi
    @gimtwi ปีที่แล้ว

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

  • @टिरंजननकले
    @टिरंजननकले ปีที่แล้ว +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..

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

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

  • @kohanokhrin
    @kohanokhrin ปีที่แล้ว

    Thanks, Antony!

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

    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?

  • @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

  • @caiocesarmelolopes2156
    @caiocesarmelolopes2156 ปีที่แล้ว

    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

  • @EUU100
    @EUU100 2 ปีที่แล้ว +1

    Thank you!

  • @PKP-vp3xq
    @PKP-vp3xq ปีที่แล้ว +5

    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 ปีที่แล้ว

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

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

      bro this is a lifesaver. I uninstalled my local postgres and I think will start using a dockerized postgres from now

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

    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.

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

    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

  • @dredogu06
    @dredogu06 ปีที่แล้ว

    Thanks Anthony

  • @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

  • @stefanovillata9658
    @stefanovillata9658 ปีที่แล้ว +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_  ปีที่แล้ว +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 ปีที่แล้ว

      @@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!

  •  2 ปีที่แล้ว +1

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

    • @anthonygg_
      @anthonygg_  2 ปีที่แล้ว

      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

  • @TattedFaceJoey
    @TattedFaceJoey ปีที่แล้ว

    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.

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

    Have you done a part three with the JWT stuff

  • @hakimchulan
    @hakimchulan ปีที่แล้ว

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

  • @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 ?

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

    The Storage here is more known as a repository. Data access layer. Postgres is in no way abstracted here when you write "Postgres" in the code.

  • @amardeepsingh1168
    @amardeepsingh1168 ปีที่แล้ว

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

  • @madebymercado5218
    @madebymercado5218 ปีที่แล้ว

    For create tables, you could consider db migration.

  • @lukaszmatuszewski
    @lukaszmatuszewski ปีที่แล้ว

    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!

  • @Punkerobmx
    @Punkerobmx ปีที่แล้ว

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

  • @foreveryoung6108
    @foreveryoung6108 ปีที่แล้ว +2

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

  • @jonathanlambrecht5642
    @jonathanlambrecht5642 ปีที่แล้ว +1

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

  • @AlexTitarenko87
    @AlexTitarenko87 ปีที่แล้ว

    Fabulous

  • @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 ปีที่แล้ว

      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

  • @notnull01
    @notnull01 ปีที่แล้ว +1

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

    • @anthonygg_
      @anthonygg_  ปีที่แล้ว +1

      Not sure. Maybe :)

  • @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!

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

    if anyone is not getting the right format of the response in post or in your localhost browser, try putting double quotes for the types like this
    ID int `json:"id"`
    FirstName string `json:"firstName"`
    LastName string `json:"lastName"`
    Number int64 `json:"number"`
    Balance int64 `json:"balance"`
    CreatedAt time.Time `json:"createdAt"`
    like this,the current version of Go does not support the old formatting method, use this format whenever declaring types. Cheers

  • @blazinglyfaster9935
    @blazinglyfaster9935 2 ปีที่แล้ว +2

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

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

    shift + escape or fn + escape

  • @eduardabramovich1216
    @eduardabramovich1216 ปีที่แล้ว +3

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

  • @TheSupahG
    @TheSupahG ปีที่แล้ว +1

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

    • @anthonygg_
      @anthonygg_  ปีที่แล้ว

      Dayum, true true. Thanks for reminding me

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

    This programming language is a struct hell )

  • @amoyou943
    @amoyou943 ปีที่แล้ว +1

    this is save foor sql injection !!!!

  • @hakimchulan
    @hakimchulan ปีที่แล้ว +2

    For the blind homies T_T

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

    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

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

    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