Golang REST API from scratch with Go Fiber, Docker & Postgres | Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 มิ.ย. 2024
  • In this tutorial, we will learn how to create a simple trivia REST API from scratch, using Go and Docker. At the end of the tutorial, we will have a little Go Fiber app connected to a Postgres database.
    📎 Text tutorials
    - divrhino.com - divrhino.com/articles/rest-ap...
    - dev.to - dev.to/divrhino/build-a-rest-...
    - Code repo - github.com/divrhino/divrhino-...
    🦏 Other great tutorials
    - Introduction to interactive Git Rebase - • Interactive git rebase...
    - Create a dad joke CLI app - • Golang Cobra CLI tool ...
    ⌛ Timestamps
    00:00 - Introduction
    00:11 - Prerequisites
    00:26 - Dockerfile and docker-compose.yml
    03:33 - Installing and managing dependencies
    08:28 - Adding a Postgres service
    16:11 - Routes and endpoints

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

  • @brad4au57
    @brad4au57 7 หลายเดือนก่อน +8

    In case anyone else is having the issue where Air is not reloading on a Windows machine, inside the .air.toml file you must set " poll=true " for the changes to be picked up in real time. Great video though!

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

      Thank you for leaving this comment! I’m sure others will find it very useful 🙏✨

    • @99baddar
      @99baddar 6 หลายเดือนก่อน

      Bro your comment saved my life thanks alot

    • @lifewiththelatchem-smiths5154
      @lifewiththelatchem-smiths5154 2 หลายเดือนก่อน

      Legend!

  • @smits7142
    @smits7142 10 หลายเดือนก่อน +4

    This is the first video I've watched where everything about Dockerfiles, docker-compose, and all of these topics finally clicked for me!

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

      Aw, that makes me happy to know! Thank you ✨✨

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

    This is truly excellent, nobody is doing this in this way in just 20 or so minutes.. great work hope to see more in the future :)

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

      Thank you for the kind words! Glad to have you here ✨

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

    This was exactly what I needed. Thank you so much!
    Good tutorial

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

      Glad you found it useful! Thanks for letting me know 🙌

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

    Exceptional, well-structured, and clearly presented. Thank you.

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

      Thank you for being here and taking the time to leave those kind words! ✨🙏

  • @alanmccarthy4004
    @alanmccarthy4004 ปีที่แล้ว +8

    This is some incredibly high quality content. I would have LOVED something like this when I was starting out. Really good clear presentation, good video structure, and wonderful brisk pace. Nice work!

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

      I appreciate your kind and encouraging comment. Thank you! 🙌

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

    My love! Thank you for the clearest explanation. OMG this is the best!

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

      Thank you so much for your lovely comment! I appreciate you watching 🙌✨

  • @rgr1regi88
    @rgr1regi88 ปีที่แล้ว +8

    This is presented so clearly! Thank you!

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

      Thank you for watching!

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

    Thank you for this 🙏🎉 I really appreciate your tutorials ❤

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

      And I appreciate you being here! I’m glad to have you 😊

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

    Absolutely loved this video and I'm amazed at the quality. Thank you for making the serious they are perfect for learning Golang. The format is perfect and you are definitely gifted at teaching

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

      Thank you! I appreciate the kind words and feedback. I hope your learning journey is going well 🙏

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

    Probably the most clear and best Go tutorial I've found on TH-cam until now. Thanks for this video.
    Also, you have a new subscriber now

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

      Thanks for your support! I appreciate you 🙏✨

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

    Thank you for cheering us up, seriously, learning can be difficult sometimes.

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

      Yes, I agree, sometimes learning can be difficult. But don’t give up! Keep coding, you can do it 🙏

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

    Very well made tutorial, thank you! It has helped me a lot!

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

      I’m so glad to hear that! Thank you for your comment ✨🙏

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

    Very clear and precise instructions, also the flow is perfectly paced. Please make more content like this. I just subscribed.

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

      Thanks for stopping by and taking the time to leave a comment! I appreciate it! ✨

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

    Explained concepts so well! Keep it up!

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

      Thank you for the encouragement! ✨❤️

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

    This is an amazing...very clear explanation. Please keep making more videos.

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

      Thank you for your kind comment! ✨🙏

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

    Amazing tutorial! Thank you for your time & efforts! Btw, your cover pages for videos are beautiful, love the way you design your videos!

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

      Thank you for leaving such a kind and encouraging comment! I appreciate you being here ✨✨

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

    amazing content, simple, high quality, got yourself a new subscriber. keep them coming!! BTW, lo ve the illustrations

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

      Aw! Thank you for taking the time to leave such a nice comment. Happy to have you here!

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

    Thank you for this! Really great tutorials!

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

      Thank you for being here! I appreciate you leaving a comment ✨

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

    This tutorial is scary good!! Thank you!

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

      Thank you for your scary nice comment! Glad you enjoyed it ✨✨

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

    your go tutorials are the best and simplest to understand! can't wait to see more go tutorials in the future~

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

      Aw, thank you for the encouragement!

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

      @@DivRhino yw~ also, would it be fine to ask for suggestions on other go tutorials? in particular, i would like yo see a rest api tutorial that uses gorilla mux, since it is a very popular go library for making near-vanilla golang rest apis. also, making a TUI application using charm bubbletea, in which i'ce heard they are a great library for making cool TUI applications~ just some suggestions, thankss

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

      @@cindrmon Thanks for the suggestions. I've played with bubbletea a couple of times in the past, so I can definitely consider making a video about it.
      I'm a little hesitant to make a video about mux as there are many good ones out there already.
      I appreciate your feedback.

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

    this is 🔥, very nicely presented
    thank you for this tutorial

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

      Thank you for watching, I appreciate you being here!

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

    This is extremely well done! The instructions are clear and concise. Great job!

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

      Thank you so much for watching!
      I’ve just finished your video “Learn to Code by NOT Doing What Everyone Else Does”. Great advice. Looking forward to seeing your channel grow 🙏✨

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

      @@DivRhino Glad you like it, thanks! I'll be going through all of your videos. It's taking me a while to get comfortable with docker. =\

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

      @@handmadegamesdev I hope you find the videos useful ☺

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

    you are indeed gifted at teaching. although i have some problems with my computer, this video helped me understand working with docker better. Thank you so much, you definetely don't have enough credit for what you do.

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

      What a thoughtful and encouraging comment 🥰 thank you, I appreciate you being here 🙏

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

    Excellent!

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

      Thank you for being here! ✨

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

    Excellent presentation - no adjective - no adverb - straight to the point with facts and monotone narrative presentation... Thank you for sharing your experience

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

      Thank you for your support! Happy to have you 🙌

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

    I know how to use docker but i didn't know this kind of magic is possible with it! Air is amazing.
    Thanks for such an awesome and clear tutorial.

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

      Thank you for the lovely comment! I’m so glad the video was useful! 🙌

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

    Lovely. Thank you

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

      Thank you for watching! 🙏✨

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

    Thank you for great tutorial

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

      Thank you for watching! 🙏

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

    We’ll done. Thank you

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

      Thank you for your continued support, 🙏

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

    Good tutorial. Thanks 🙏

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

      Thank you for watching! Glad to have you ✨✨

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

    Great tutorial!

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

      Thank you for your encouraging comment! 🙏

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

    Excellent job.

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

      Thank you for watching! I appreciate the comment ✨🙏

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

    very good. Subscribed!

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

      Thanks for being here!

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

    Thanks for this tutorial it helped me to understand how to use docker with golang💫💫

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

      And thank you for watching! So glad you found the content useful 🙏

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

    Thank you so much❤

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

      And thank you for watching 😍🙏

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

    Thank you !

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

      And thank you for watching!

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

    this is great

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

      Thank you for watching! 🙏

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

    excellent video.

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

      Appreciate the comment! Thanks for being here ✨🙏

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

    Subbed. Great content

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

      Just a suggestion would be to make the text size a bit larger so it's easily visible in the video

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

      Thank you for being here! And thanks for the feedback. I’ll make the text bigger next time. 🙏

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

    Amazing, Following closely

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

      Thank you for taking the time to leave a comment. I appreciate you being here 🙏

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

    Decided on learning Go so will be visiting your channel often, could you please zoom in a bit

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

      Thank you for the feedback, I’ll make sure to zoom in for all future videos. I’m glad you’re here, I hope you find something useful 🙏✨

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

    Thank you

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

      Thank YOU for being here! 🙏

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

    lovely

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

      Thank you 🙏

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

    this is great, one suggestion is zoom in more into the editor

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

      Thanks for the feedback. I’ll keep this in mind for all future videos 🙏🙏

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

    Hey Div Rhino! Long time. wb

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

      Hey Big Squeak! Thank you 🥰

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

    great video, i'm very appreciated with your dediation that you put into making these videos. And it can be more wonderful if there is any solution for not hot reloading while using windows ?

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

      Hello there, thanks for leaving a comment. Several Windows users have reported similar issues with hot reloading when using docker. Here's a link to a potential workaround I found in the air repository:
      github.com/cosmtrek/air/issues/190#issuecomment-999254716

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

    15:12 log.Fatal() is like .Println() followed by os.Exit(1) so no need of os.Exit(2)

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

      Cool. Thanks 🙏

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

    Good tutorial, for the next one try to zoom to the desktop.

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

      Thank you for the feedback 🙏

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

    Should I run this command (docket compose build) whenever I updating docker-compose.yml or Dockerfile?

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

      Thanks for your question. If you’re adding new steps to your Dockerfile, you should run the build command. Images are static once they are built and they do not automatically update themselves when new instructions are added. So every time you add something new to the Dockerfile, you’ll want to rebuild.
      docker-compose is a tool that allows you to work with multiple Dockerfiles in the one project. You don’t usually need to rebuild an image when you change the config there. But sometimes you may need to restart your server.
      I hope that helps 🙏✨

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

    I have a go project and I was making a docker image. It build successfully but when I tried to run it, .env file was not actually copied in the docker image. How can we copy the file name starting with dot.

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

      Have you added a COPY instruction to your Dockerfile to copy over the .env file?

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

    I have an issue "too many open files" when run docker compose up, can you help me! Thanks

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

      Hi there! Thanks for your comment. I'm sorry to hear that you're having trouble. I found an answer on stackoverflow that may help you out:
      stackoverflow.com/a/43265189

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

    at 4:17 the go.mod file doesnt appear on my project board... i can see it with "ls" but i cant see anything i create in the container

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

      Hi there! I'm sorry to hear you're having trouble with this. Are you by any chance using a Windows machine?

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

    air is not hot reloading, my vscode has the auto save feature, I tried disabling it but still is not working. Any ideas?

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

      Hello there, are you on a Windows machine? I have seen other people online having issues with using the air package in Docker on a Windows machine. I am not sure how to use docker on Windows, unfortunately.

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

      @@DivRhino yes I am on windows :( any alternatives?

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

      @@manuelillanes1635 I found this open issue in the Github repo and it looks like someone there has come up with a solution.
      Give it a try, maybe?
      github.com/cosmtrek/air/issues/190#issuecomment-999254716

  • @ingedison1
    @ingedison1 17 วันที่ผ่านมา

    I can't connect to the db, := failed to connect to `host=localhost user=postgres database=`: dial error (dial tcp [::1]:5432: connect: cannot assig432: connect: cannot assign requested address), i created a new one, but doesnt worth...

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

    Hey.... hot reload it not working in docker windows 11 :(

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

      Hello there, unfortunately this seems to be an issue that others have also faced when using air with docker-compose on a Windows machine. 😥

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

    DB CONNECTION DIDN'T WORK - failed to initialize database, got error failed to connect to `host=db user=test database=test`: failed SASL auth (FATAL: password authentication failed for user "test" (SQLSTATE 28P01))

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

      Sorry to see that this isn’t working for you. Without seeing your code, it would be difficult to see where the issue is occurring. I have linked the text tutorial and the finished code in the video description. It may help to compare your code with that to see if you can spot the differences.

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

      Same here, any solutions?

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

      Did you find a solution? I'm having the same issue.

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

      ​@@manuelillanes1635 I solved it removing volume and running prune to clean all local data related to volumes.

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

    this is need to install golang in linux first?

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

      Hello! You do not need to have Golang installed first. But you do need to have Docker installed and running to be able to follow the tutorial.

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

      @@DivRhino thanks for the reply, so we can configure for go specific version from dockerfile right?

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

      @@muhamadrifqi5709 Yes, that's right. Once you have docker installed on your machine, you will use the Dockerfile to specify which Golang version you want to install.

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

    how to check database ?

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

      Hey there, thanks for your question. You can use a database client like Postico, Navicat or DBeaver to check your database in a GUI.
      You can also use psql if you prefer to work in the terminal.

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

    You should make the fonts bigger, it is hard to read.

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

    how worck withot GORM?????

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

      If you don’t want to use an ORM like GORM, you can write SQL.

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

    Can you do a urfave2 tutorial?

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

      Hello Marvin, good to see you again. Thanks for leaving a comment. Do you mean urfave/cli?

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

      @@DivRhino oh you remember me. I’m still learning go and need help with api lol. Yes urfave. Cli

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

      That will be a big help. Thank

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

    please increase font size in the video for your blind homies

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

      Thank you for the feedback! Yes, unfortunately many people struggled with the small font size, sorry about that. I will make it bigger for all future videos. 🙏🙏

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

    use a larger font. i need my eyes

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

      Okay

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

    Very well explained. Could you please increase the font size of your IDE ? It's hard to see on the mobile.

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

      Thank you for watching! And I apologise for the small IDE text size. I'll keep mobile in mind for future tutorials. I appreciate the feedback 🙏

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

      @@DivRhino thank you