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

Поділитися
Вставка
  • Опубліковано 26 лип 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

КОМЕНТАРІ • 156

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

    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  Рік тому

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

  • @tobiadeniji6630
    @tobiadeniji6630 19 днів тому +1

    Okay, that's a good one. Absolutely informative and concise.

    • @DivRhino
      @DivRhino  18 днів тому

      Glad you enjoyed it! Thanks for taking the time to leave a kind comment 🙏✨

  • @dcxwms2151
    @dcxwms2151 6 місяців тому +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  6 місяців тому +1

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

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

    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  9 місяців тому

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

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

      Bro your comment saved my life thanks alot

    • @lifewiththelatchem-smiths5154
      @lifewiththelatchem-smiths5154 4 місяці тому

      Legend!

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

  • @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 Рік тому +1

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

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

      Thanks for your support! I appreciate you 🙏✨

  • @rgr1regi88
    @rgr1regi88 Рік тому +8

    This is presented so clearly! Thank you!

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

      Thank you for watching!

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

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

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

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

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

  • @34556ndmd
    @34556ndmd 4 місяці тому +1

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

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

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

  • @prasanthbupd
    @prasanthbupd 10 днів тому +2

    one of the great videos I have ever seen

    • @DivRhino
      @DivRhino  9 днів тому

      What a nice thing to say! Thanks for watching, I appreciate your kind words ✨🙏

    • @prasanthbupd
      @prasanthbupd 3 дні тому

      @@DivRhino keep up the good work expecting more videos 😄😄

  • @sirrus3009
    @sirrus3009 5 місяців тому +1

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

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

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

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

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

  • @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 Рік тому +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  Рік тому +1

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

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

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

    • @DivRhino
      @DivRhino  8 місяців тому

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

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

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

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

      Thank you for watching, I appreciate you being here!

  • @nikitakhabya3894
    @nikitakhabya3894 5 місяців тому +1

    Explained concepts so well! Keep it up!

    • @DivRhino
      @DivRhino  5 місяців тому +1

      Thank you for the encouragement! ✨❤️

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

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

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

      Thank you for your kind comment! ✨🙏

  • @nickshilov9929
    @nickshilov9929 5 місяців тому +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  5 місяців тому

      Thank you for leaving such a kind and encouraging comment! I appreciate you being 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 9 місяців тому

    This tutorial is scary good!! Thank you!

    • @DivRhino
      @DivRhino  9 місяців тому

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

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

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

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

    very good. Subscribed!

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

      Thanks for being here!

  • @ubitubee
    @ubitubee 11 місяців тому +1

    Lovely. Thank you

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

      Thank you for watching! 🙏✨

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

    Excellent!

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

      Thank you for being here! ✨

  • @MrVipulLal
    @MrVipulLal 11 місяців тому +1

    Good tutorial. Thanks 🙏

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

      Thank you for watching! Glad to have you ✨✨

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

    Great tutorial!

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

      Thank you for your encouraging comment! 🙏

  • @cornevanstraten7664
    @cornevanstraten7664 11 місяців тому +1

    Excellent job.

    • @DivRhino
      @DivRhino  11 місяців тому +1

      Thank you for watching! I appreciate the comment ✨🙏

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

    excellent video.

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

      Appreciate the comment! Thanks for 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 🙏✨

  • @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 11 місяців тому

    Thank you so much❤

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

      And thank you for watching 😍🙏

  • @fullstack_journey
    @fullstack_journey 11 місяців тому +1

    Subbed. Great content

    • @fullstack_journey
      @fullstack_journey 11 місяців тому +1

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

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

      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 🙏

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

    Thank you !

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

      And thank you for watching!

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

    Hey Div Rhino! Long time. wb

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

      Hey Big Squeak! Thank you 🥰

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

    Thank you

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

      Thank YOU for being here! 🙏

  • @programmertelo
    @programmertelo 4 місяці тому +1

    this is great

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

      Thank you for watching! 🙏

  • @CMT-p6q
    @CMT-p6q 11 місяців тому +1

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

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

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

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

    lovely

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

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

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

      Cool. Thanks 🙏

  • @bachphanvan3361
    @bachphanvan3361 Рік тому +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  Рік тому

      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

  • @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 Рік тому

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

    • @DivRhino
      @DivRhino  Рік тому +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 🙏✨

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

  • @ingedison1
    @ingedison1 Місяць тому

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

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

    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  7 місяців тому

      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

  • @alp6742
    @alp6742 Місяць тому +1

    This is an amazing tutorial but I have a question. I'd like to change run command with an environment variable in docker-compose.yml is that possible?

    • @DivRhino
      @DivRhino  Місяць тому

      Thanks for your question!
      There are some suggestions in this StackOverflow thread:
      stackoverflow.com/questions/40447029/docker-compose-environment-variable-for-command

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

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

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

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

    how to check database ?

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

      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.

  • @faizulla5838
    @faizulla5838 9 місяців тому

    how worck withot GORM?????

    • @DivRhino
      @DivRhino  9 місяців тому

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

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

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

  • @cozkul
    @cozkul 11 місяців тому +1

    please increase font size in the video for your blind homies

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

      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. 🙏🙏

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

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

  • @pooulad
    @pooulad 8 місяців тому

    use a larger font. i need my eyes

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