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

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

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

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

    👉 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

  • @Jam-ht2ky
    @Jam-ht2ky ปีที่แล้ว +39

    this tutorial was unbealiaveble. The amount of things you managed to fit in one 30 min videos! thank you

  • @shleebeez
    @shleebeez ปีที่แล้ว +32

    i like how you pointed out your usage of a decorator so we can use our handler as an http one without explicitly modifying it. you should keep pointing out useful patterns and such like that, it's very helpful

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

    This video is a clear example of "from 0 to hero in 30 mins"

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

      Kissass

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

      Not from 0, you already have to know the basics of GO to understand it

  • @سيماوافلامومسلسلاتوترندات

    Anthony you are awesome in teaching golang on youtube
    we need more contect about golang especially projects like that
    Thanks again for your big and helpful effort

  • @annusingh4694
    @annusingh4694 ปีที่แล้ว +21

    Your content is so powerful! Very helpful in terms of quality and speed. I'm learning so much at such high speed. Plus the teaching style is engaging, you make the students think which is way better than a scripted tutorial. Thank you so much 😊

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

      Thank you ❤️

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

    Hallo Anthony, bedankt voor deze training, dankzij jou heb ik Golang ontdekt en ik heb er echt van genoten.
    Je doet het heel goed en je bent een goede leraar, ook Belg, dat is een plezier! Tot ziens in de laatste aflevering!

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

    Jij bent echt een baas man! Ik kan uren naar je nuchtere video's kijken man. Petje af!

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

      Ha! Thanks !

  • @nesssel
    @nesssel 7 หลายเดือนก่อน +11

    In case someone is still confused about why the Content-Type wasn't applied properly, it's because WriteHeader(200) starts writing to the connection and sends all headers set up to that point. Headers set after calling it are simply ignored.

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

    Your teaching style is second to none!

  • @AbhishekKumar-kk6qs
    @AbhishekKumar-kk6qs 11 หลายเดือนก่อน +2

    for 24:29, You can just select the option of JSON in postman, It will show the data in JSON format.

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

    im glad i found your channel!

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

    Best channel for golang especially backend thank you sir

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

    Hey King, you dropped this 👑

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

    While learning go these days, i worked on this mini project with the official net/http package, thanks for the idea

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

    This is the best go API tutorial I've ever watched. Thank you so much for your awesome content and for teaching us the best practices 🔥

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

    Amazing video, so informative, I like your rhythm and enthusiasm, congrats from Brazil xD

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

    Thanks for the video, much appreciated.
    Learning go, so seeing someone work from scratch is more useful than you would believe!

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

    Man! you are the Top G of Golang

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

    I got stuck within the 5 minute mark since I didn't have proper understanding of Handler, HandleFunc, HandlerFunc and all and I kept digging through documentation, videos and ChatGPT until I understood that they exactly do the same thing just in a different way. i am learning writing idiomatic Go and yes you explain good. And yes I immediately figured out why the Content-type wasn't set in the response headers. 😂

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

    this is just epic, love the Bob Ross references

  • @asutoshpanda1508
    @asutoshpanda1508 ปีที่แล้ว +16

    please collect all your projects into respective playlist, it's really difficult figure out which video belongs to which project
    all streamed video projects, recorded projects with proper naming convention(part-1,2,3 etc) and if all could be accessible from playlist button then that will be really helpful.
    hope you will get some time to do this housekeeping activity Anthony.
    thanks for all the efforts Anthony, you have created energy and interest in me to learn golang.

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

      Will do this over the weekend. Thanks for the feedback

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

    echt een held je bent toch uit België ik hoor het aan sommige woorden ben goed met veel talen maar probeer nu go lang te leren en deze tutorial heeft hard geholpen

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

    Hey , didn't know Johnny Sins was also a developer
    Jokes aside, awesome tutorial man, I'm getting started with go an seeing you gliding through helped me a lot with the understanding of the language

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

      Johnny is a versatile actor

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

    Thanks man. Hands-on content 🤘

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

    These videos are incredible. Thank you. :)

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

    With your lessons, I am slowly falling in love with Go😂

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

    Thankyou for a Gin free API development tutorial

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

    With the mux router you can specify the method for the route 15:41
    router.HandleFunc("/accounts", makeHTTPHanlerFunc(s.handleGetAccount)).Methods("GET")

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

    Great video!

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

    Love the style and the approach to teaching. Excellent stuff, please keep it up

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

    Pro-ject. I like it

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

    Moving too fast, can't keep up with all the great content Anthony is creating.🚀🔥

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

    You are from gold man!💪

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

    Great content. Thanks!

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

    Thanks for your content!
    One question I have, is there a reason in the handlers to return a reference (&Account{}) instead of just Account{}?

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

      Maybe we need to update state. Maybe

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

    amazing 🚀

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

    Why don't you use lowerCamelCase convention for naming methods and vars? I'm completely new to golang and that seems very odd, is there a different convention for go?

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

      Lowercase methods are private. Uppercase are public. I know, super awkward

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

    can you further explain why you decided to make a wrapper api function? did you just not want to handle the error in each different account handle function and rather handle it in one location?

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

    Awesome!

    •  2 ปีที่แล้ว

      And yeah, you're freaking fast! :D

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

    Thanks for this amazing tutorial! Quick question:
    For mux routers, they have a function called Method that lets you decorate the handler with accepted HTTP methods. Could we use that instead of having a generic handle function for handling the method types?

  • @CMT-p6q
    @CMT-p6q ปีที่แล้ว

    thank you for this super valuable appreciate the hard work here

  • @HuzaifSayyed-t9r
    @HuzaifSayyed-t9r 18 วันที่ผ่านมา

    23:30 REASON WHY Content-Type is not application/json
    The reason your response is returning Content-Type: text/plain; charset=utf-8 instead of Content-Type: application/json is likely due to the order of operations. Specifically, the HTTP status header is being written before you set the Content-Type header.
    When w.WriteHeader(status) is called (explicitly or implicitly), it sends the HTTP headers to the client. If you set w.Header().Set() after calling w.WriteHeader(), the header changes won't take effect.
    You need to ensure that the Content-Type header is set before any call to w.WriteHeader() or before writing to the ResponseWriter. Here's the corrected implementation:
    ```
    func WriteJSON(w http.ResponseWriter, status int, v any) error {
    // Set Content-Type header to application/json
    w.Header().Set("Content-Type", "application/json")
    // Write status code and encode the response as JSON
    w.WriteHeader(status)
    return json.NewEncoder(w).Encode(v)
    }
    ```

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

    thank you for this tutorial! is excelent and help me :D

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

    I just started to learn Golang from a crash course before this, but the naming is confusing to me. There is apiFunc, ApiError and APIServer? the explanation is clear though.

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

    How do you go inside functions? What is the shortcut?

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

    so Go is better for rest api or Rust? thank you

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

    are you using a vim plug in for vs code? Which plug in?

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

      The default official one

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

    Hi Anthony thanks for the video I got one question. You mentioned about circular dependency and no need to create multiple folders/packages. So how do you structure your code is some architecture like (clean, hexagonal) recommended in Go? Or what do you suggest let's say you are handling big project. I really appreciate if you just give me some comment on it. Thanks.

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

      Hi! My rule of thumb is to only create packages when you need to, otherwise, just keep things in the root folder.
      Think about this, if you have 100 files in separate packages or 100 files sitting in the root folders, you will still end up with 100 files right? Also, your program will not run better or faster with more packages. It is just an ancient old scam by people that have no value to bring to the table, so they try to trick you with some "architectural" bullshit.
      Look at the Redis codebase, for example, that is being used by millions of companies in production. All files live in the src folder.
      I hope this answer helps you!

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

    I thought Johny Sins has started teaching programming 😂 Although, very useful tutorial, thanx a lot!

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

    What part of the video covers docker?

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

    Really valubale and High quality content . Just one thing please : can you make the code font just a bit bigger to be easier to see ?

  • @AhmedMahmoud-f3y2x
    @AhmedMahmoud-f3y2x 11 หลายเดือนก่อน

    Hey Anthony, great great work, I leaned a ton! so thank you :)
    I have a question tho, you created this interface `Storage` which is passed to the apiServer struct, which is good, but now If I want to add another path say (/products), I will need to create the handle funcs for the product, but then the interface won't work anymore because it's just for the accounts. How create a general interface that can implement all handlefuncs of different business logics
    Thank you :)

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

    Any tips how to get postman to send request? At 23:30

  • @AnuragSaikia-qi2lb
    @AnuragSaikia-qi2lb 7 หลายเดือนก่อน +1

    hey the reason your content type was not "application/json" is because you called writeheader before header.set When you call WriteHeader(statuscode) you set the status code and send the status line and all the headers to the client thus not being able to set headers after it

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

    Thanks for this great guide ! If you had to redo this with a differernt router than Mux, that is no longer maintained, which would you have chosen and why ?

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

      Echo. Because I use this.

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

    Would be nice to hear your recommendations now that mux is no more

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

    Hello,. Thank you for your content it's very interesting. I see that all your project you start with Makefile. On some of your videos I saw the MS Windows start button. Which make do you use?

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

    To solve the JSON content format you have to set headers before writing
    ```go
    w.Header().Set("Content-Type", "application/json")
    w.WriteHeader(status)
    ```

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

    What logger do you use?

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

      Think its logrus "github.com/sirupsen/logrus"

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

      Thanks! Great video btw..

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

    i'm new to golang and i didn't understand everything but obviously i'll watch this video 10 times to understand everything
    but 1 question why you don't use Neovim ?

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

      Used vim for years. But VSCode customized is just so good. No hassle spending hours configuring. Syncs with all my machines. But neovim is good, its just not worth my time setting it up again. And vscode scales nice for recording also.

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

    Request, make video like this again please.,, it beautiful

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

    Please make a tutorial with rust+axum for same project.

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

    Would be amazing if Unit Tests would be also covered

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

    Why mux and not gin for example?

  • @GabrielRodrigues-sm3dr
    @GabrielRodrigues-sm3dr ปีที่แล้ว +1

    Really good content! I'd like to know what is your code editor theme. ✌

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

    Hello Anthony, thanks for the tutorial! BTW are you Turkish? My assumption in based on your soft pronunciation of `R`s in word endings, am I right?

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

    Awesome tutorial. How can i implement authentication in this api. a sign in and sign out route.

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

    please also include nosql database too..thank you for starting this.

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

      We will set the project up so that adding new types of storage can be implemented easily!

  • @GggGgg-t2x
    @GggGgg-t2x 10 หลายเดือนก่อน

    great stuf!

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

    Did you find what's was wrong with content-type?

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

      I think it was header.Add that was the cullprit

    • @fannigurt
      @fannigurt ปีที่แล้ว +4

      @@anthonygg_ If you write bytes to the response, then you cannot write a header after the fact. So first setting headers then WriteHeader for status. It will work! 😌

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

      @@fannigurt Dayum this is so true! Thanks for this!

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

    Amazing video but you should ditch make for go-task... It's a task runner built in go.

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

    where are you from?

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

    make run not work for me

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

    Thumbnail 😂 👌

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

    Very good video but the library used here is no longer mantained, be carefull!!.

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

    15:25

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

    an time i watch your videos i stop the video maybe 232343 😅😅 time to understand what are u do ,thank you

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

    16:20 "Hey boss*, I've accidentally deleted production DB and then all backups .. it was a happy little accident" ( ͡° ͜ʖ ͡°)
    * Rob Boss

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

    Yes, you are "fast" but that is not always best when you are aiming to teach others and do a tutorial on something, I agree that being fast is amazing (for many things), I am 140-145 wpm typist (you are probably even faster than this) and I am also a vim user for many years. It was really hard to follow this video, had to stop it multiple times. However, good quality video anyways

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

    I am still stuck at understanding your error handling methods. I think they need their own session

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

    pretty please, needs to be zoomed in for the mobile users

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

      Zoom your phone or pay me money

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

    Please zoom in when you're coding! I can barely see the code!

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

      200 dollars

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

      @@anthonygg_ Fine! Send me your Cliq and I'll wire them!

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

    The guy doesnt give the fish but teaches how to catch it

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

    Yo, t'es francophone ?

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

    OMG!

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

    I'm afraid of using golang web framework. My fear is that in some day they will just stop being maitained and booom! need to migrate

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

    in 30 min? ok let me see this

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

      I think this is part 1 😢

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

    Look is American but the sound is indian

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

    You look like Dwayne rock Johnson in far 😅

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

    this dude sounds scottish

  • @ГидраЛиск
    @ГидраЛиск ปีที่แล้ว +1

    DO NOT WASTE U TIME, the video series is not complete. You can check out part 5 comments, 7 month ago this guy promised a new video in 2 weeks and never delivered. The video series stops at authorization, it doesn't get to the banking API. The code he wrote during these 5 tutorials has a lot of temporary solutions, which he promises to fix in future videos that don't exist. It's ridiculous it's called a COMPLETE JSON API, I have no idea why there is so much positive feedback here, it's a scam

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

      The bastard! Lets call the police.

    • @ГидраЛиск
      @ГидраЛиск ปีที่แล้ว

      @@anthonygg_ Yeah, yeah, very funny. Waste your viewers time and then mock them in the comments

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

    Hi @anthonygg_ could i ask you, what is your vscode theme?

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

    gorilla mux is dead any good alternative recomendation.

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

      Fiber , echo or maybe gin all three are solid